An expression can be recursively defined as:
expression := <name> | <function> | <application>
function := λ<name>.<expression>
application := <expression> <expression>
λx.x
identity function
.x
has no meaning on its own.
(λx.x) y -> [y/x]y -> y
[y/x]
is the transformation notation which indicates to replace all occurrences of x with y .name
is said to be bound
in a function if is defined in the function name (preceded by λ
).
λx.x
-> x is bound as it defined in the function name.λx.xy
-> x is bound but y is not as it is not defined.name
can be both bound and free in an expression.
(λx.xy)(λy.y)
-> y is free
in the left expression while it is bound in right expression.(λx.x)(λy.y) -> [(λy.y)/x]x -> λy.y
(λx.(λy.xy))y -> [y/x]λy.xy ->λy.yy
z
.(λx.(λz.xz))y -> [y/x]λz.xz ->λz.yz
(λx.(λy.(x(λx.xy))))y
-> (λx.(λz.(w(λx.xz))))y
->[y/x]λz.(w(λx.xz))
-> λz.w(λx.xz)
succ(succ(zero))
where succ
is a function which can be written as λs.s+1
. In other words numerals are represented in the form of 1+..+1+0
0 = λsz.z
-> 01 = λsz.s(z)
-> 1+02 = λsz.s(s(z))
-> 1+1+0λwyx.y(wyx)
Lets try to increment zero (λsz.z)
(λwyx.y(wyx))(λsz.z) -> [(λsz.z)/w]yx.y(wyx) -> λyx.y((λsz.z)yx)
-> λyx.y(z) ; which is of form λsz.s(z)