Church integer

Church integer

(theory)A representation of integers as functions invented byAlonzo Church, inventor of lambda-calculus. The integer Nis represented as a higher-order function which applies agiven function N times to a given expression. In the pure lambda-calculus there are no constants but numbers can berepresented by Church integers.

A Haskell function to return a given Church integer could bewritten:

church n = cwherec f x = if n == 0 then x else c' f (f x)wherec' = church (n-1)

A function to turn a Church integer into an ordinary integer:

unchurch c = c (+1) 0

See also von Neumann integer.