DEV Community

Discussion on: Daily Challenge #249 - Incremental Changes

Collapse
 
craigmc08 profile image
Craig McIlwrath

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)))))))))))))))))))))))))))))))))))))))))))))))))))