Comment

Comment by tromp

Note that with the standard representation of natural numbers in lambda calculus, the Church numerals [1], you don't even need the Y combinator to implement factorial:

    fac = λn.λf.n(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x)
For example, applied to Church numeral 3 this gives (with F=(λf.λn.n(f(λf.λx.n f(f x))))):

    fac 3 = \f. F (F (F (\x.f))) 1
          = \f. 1 (F (F (\x.f))  2)
          = \f. 1 (2 (F (\x.f)   3))
          = \f. 1 (2 (3 ((\x.f)  4)))
          = \f. 1 (2 (3 f))
which is the Church numeral for 1*2*3 = 6.

[1] https://en.wikipedia.org/wiki/Church_encoding

parent tromp 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton