loading...

re: Daily Challenge #249 - Incremental Changes VIEW POST

FULL DISCUSSION
 

Thought I'd give this a try using plain lambda calculus. The notation is:

  • λx.t = Function taking x as an argument and producing the expression t. Can simplify λx.(λy.t) -> λx y.t
  • MN = Apply N to M
  • Application is left-associative, ex. MNO = (MN)O
0 = λf x.x
succ = λn f x. f (n f x)
add = λm n f x. m f (n f x)
mul = λm n f x. m (n f) x
alg = λn i s. add n (mul i s)

Example 1:

2 = succ (succ 0)
5 = succ (add 2 2)
10 = add 5 5
alg 2 5 10
--> λf x.f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f x)))))))))))))))))))))))))))))))))))))))))))))))))))
code of conduct - report abuse