Readings: Scott, ch. 10 (including 10.6.1 on the CD), Dybvig ch. 1,2 (optional)
λ-Calculus
A Turing complete model of computation that has its syntax and reduction rules. It is the basis for functional languages.
Syntax
ç-calculus has variables, abstraction and application.
Variables: lower-case letters. Such as x.
Abstraction: (definition of function) λx.M, x being the function parameter, M being the function body.
Application: (invocation of function) M N. Call function M with the argument N.
Abstraction is right-associative, application is left-associative. And application has precedence over abstraction. (For example,λx. y λx. z means λx.(y (λx.z)))
Free and bound variables
In term λx.M, the scope of x is M. So, we call x bound in M. The variables that are not bound are free.
α-conversion
Renaming bound variables. Usually used to avoid name collision.
λy.(...y...) → λw.(...w...)
β-reduction
Applying the argument and calling the function.
[x→N]M means M with all bound occurences of x replaced by N.
Restriction: N should not have any free variables which are bound in N.
Normal form
An expression that cannot be β-reduced any further is a normal form.
Not everything has a normal form. For example, (λz.z z)(λz.z z) reduces to itself which will result in infinite application.
Evaluation strategies
Slide page 7
For example, (λx.λy.yxx)((λx.x)(λy.z))
normal-order: reduct the outermost "redex" first.
2.applicative-order: arguments to a function evaluated first, from left to right.
Some observations:
If a lambda reduction terminates, it terminates to the same reduced expression regardless of reduction order.
If a terminating lambda reduction exists, normal order evaluation will terminate.
η-reduction
η(eta)-reduction is used to eliminate useless variables.
Computational power
The untyped λ-calculus is Turing complete.
Numbers and numerals: number is an abstract idea, numeral is the representation of a number.
ISZERO ≡ λn.n(λx.FALSE)TRUE
SUCC ≡ λnfx.f(nfx) // n+1
PRED ≡ λn.n(λgk.(g⌜1⌝)(λu.PLUS(gk)⌜1⌝)k)(λv.⌜0⌝)⌜0⌝ // n-1
PLUS ≡ λmnfx.mf(nfx) // m+n
MULT ≡ λmnf.m(nf) // m*n
EXP ≡ λmn.nm // n^m
MUL = λmn.m (ADD n) 0
EXP = λmn.m (MUL n) 1
(car '(this is a list of symbols))
=> this
(cdr '(this is a list of symbols))
=> (is a list of symbols)
(cdr '(this that))
=> (that) ; a list
(cdr '(singleton))
=> () ; the empty list
(car '())
=> Error: car expects argument of type<pair>; given()
(cons 'this '(that and the other))
=> (this that and the other)
(cons 'a '())
=> (a)
(quote (1 2 3 4))
(quote (Baby needs a new pair of shoes))
'(this also works)