// Functions const identity = x => x; const succ = n => f => x => f(n(f)(x)); const pred = n => f => x => n(g => h => h(g(f)))(u => x)(identity); const If = Condition => Then => Else => Condition(Then)(Else); const not = x => If(x)(False)(True); const and = p => q => p(q)(p) const lessOrEq = x => y => (function leq(a) { return b => If(isZero(a)) (() => True) (() => If(isZero(b)) (False) (leq(pred(a))(pred(b))())); })(x)(y)(); const equal = x => y => and(lessOrEq(x)(y))(lessOrEq(y)(x)); const isZero = n => n(x => False)(True); const churchToInt = n => n(x => x+1)(0); // Values const True = x => y => x; const False = x => y => y; const zero = f => identity; const ten = succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero)))))))))); let x = churchToInt(function f(i) { return If(equal(i)(ten)) (() => i) (() => f(succ(i))()); }(zero)());