I use lambda calculus with javascript. I gonna try to show some little example, how the SUCC
and the function B
aka Bluebird/Compose works and can be combosed.
First a little reminder with Church-Numerals (in JS):
const n0 = f => x => x
const n1 = f => x => f(x)
const n2 = f => x => f(f(x))
const n3 = f => x => f(f(f(x)))
and the Succesor SUCC := λnfx.f(nfx)
for the Church-Numerals in JS:
const succ = n => f => x => f( n(f)(x) )
.
We can see that the succ
-Function just takes a Church-Numeral and add a f
before, so that a succ(n1)
with the body f(x)
would be f(f(x))
. Therefore, it ends up doing 1 + n compositions of f
in total.
// example creating new Church-Numbers with the Succesor-Function
const n4 = succ(n3)
const n5 = succ(n4)
// or do Addition with Church-Numbers
const n7 = n2(succ)(n5)
const n10 = n5(succ)(n5)
//to test if it works, us the helper-function churchtoJsNum
const churchtoJsNum = n => n(x => x + 1)(0)
churchtoJsNum(n10) // 10
There is another way to write successor, because we are doing n-fold compositions: a compose function. Smullyan named this the Bluebird after Curry’s B
combinator.
B := λfgx.f(gx)
in JS: const B = f => g => x => f(g(x))
Now can combine the succ
and B
-Function.
const succ = n => f => x => B(f) (n(f)) (x)
Now that we have an actual composition function, we can define successor without mentioning the final x value argument.
const succ = n => f => B(f)(n(f));