Recursion in lambda Calculus

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Assume you want to write a recursive function that returns the factorial of a natural number. You might attempt something like:

F = Ln.(((If-then-else)(Zero?)n)1)((*)n)(F)(Pred)n
 

*This, however, does not work as explicit self-references are not permitted.
 
*Fortunately, the problem can be solved using the so-called fixed point operator (also called paradoxical operator or Y combinator):

Y = Ly. (Lx.(y)(x)x) Lx.(y)(x)x
 

*Applying Y on a simple example:
 
> (Y)f
(L y. (L x. (y) (x) x) L x. (y) (x) x) f
---> (L x. (f) (x) x) L x. (f) (x) x
---> (f) (L x. (f) (x) x) L x. (f) (x) x
---> (f) (Y)f

*Note that the use of Y would immediately end up in an endless recursion in case of right-most order evaluation. Scheme permits self-referential definitions instead.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2002 Andreas Borchert, converted to HTML on May 02, 2002