 # assigning value 10 to x

Mar 5th, 2021 (edited)
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // Functions
2. const identity = x => x;
3. const succ = n => f => x => f(n(f)(x));
4. const pred = n => f => x => n(g => h => h(g(f)))(u => x)(identity);
5. const If = Condition => Then => Else => Condition(Then)(Else);
6. const not = x => If(x)(False)(True);
7. const and = p => q => p(q)(p)
8. const lessOrEq = x => y => (function leq(a) {
9.                                 return b => If(isZero(a))
10.                                                 (() => True)
11.                                                 (() => If(isZero(b))
12.                                                         (False)
13.                                                         (leq(pred(a))(pred(b))()));
14.                             })(x)(y)();
15. const equal = x => y => and(lessOrEq(x)(y))(lessOrEq(y)(x));
16. const isZero = n => n(x => False)(True);
17. const churchToInt = n => n(x => x+1)(0);
18.
19. // Values
20. const True = x => y => x;
21. const False = x => y => y;
22. const zero = f => identity;
23. const ten = succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero))))))))));
24.
25. let x = churchToInt(function f(i) {
26.   return If(equal(i)(ten))
27.             (() => i)
28.             (() => f(succ(i))());
29. }(zero)());
RAW Paste Data