Y combinator
- The y combinator is a way to implement recursion in lambda calculus
- Most basic recursion representation:
loop = loop
- Consider representing “loop” in lambda calculus (the “omega combinator”):
- the function takes an input and returns as output
- we apply this function to itself
- this concept of “self application” is the key to recursion
simple example:
- expanded:
- result:
general example:
a definition of “rec” in lambda calculus (y combinator):
- note that the y combinator includes the same sort of “self application” or “omega combinator” included in “loop”, though the y combinator is not itself recursive because it relies on the input, which is the function that should be recursed
- as the “omega combinator” is applied to itself, expanded, and evaluated, it naturally calls the function input each time it’s evaluated, allowing for recursion