| |||||||||
A Church integer is a representation of natural numbers as functions, invented by Alonzo Church as part of his lambda calculus. The natural number n is represented as a higher-order function, which takes a function f as argument and returns the n-fold composition f o f o ... o f as result.
For example, in Haskell, a function that returns a particular Church integer might be
The transformation from a Church integer to an integer might be
Thus the (+1) function would be applied to an initial value of 0 n times, yielding the ordinary integer n.
See lambda calculus for another expression of the same idea.
There are some interactive examples of Church integers .