Contract.js is a JavaScript translation of [Contracts as Pairs of Projections] 1.
function evenp (x) { return (x % 2) === 0 };
function oddp (x) { return (x % 2) === 1 };
oddin_oddout = ho(flat(oddp), flat(oddp));
oddin_oddout_evenout = ho(ho(flat(oddp), flat(oddp)), flat(evenp));
Note: the callee is called "server", the caller "client".
p1 = guard(oddin_oddout,
function (y) { return y },
"server", "client");
p2 = guard(oddin_oddout,
function (y) { return y * y - y },
"server", "client");
p3 = guard(oddin_oddout_evenout,
function (f) { return f(1) },
"server", "client");
p1(2); // Error: client violates the contract
p2(3); // Error: server violates the contract
p3(function (x) { return x + 2 }); // Error: server violates the contract
It would be nice to have a contract checking library à la [Racket's contract system] 3.