Lecture: Lambda the Magnificent
Background Material
- Lecture on functional programming and scheme.
Reading
- Chapter 10 (sec. 6) of the text (lambda calculus)
- The scheme reference manual available with
MIT-Scheme
Theme
The semantics of a pure functional programming language can be mathematically
described by a substitution process that mimics our understanding of
function application - i.e., substitute all occurrences of the formal parameters
of a function in the function body by the arguments in the function call.
In order to formally study function definition and application and
computability, logicians (Alonzo Church, Stephen Cole Kleene, and others)
in the 1930s developed a formal notation called the lambda calculus and rules
defining an equivalence relation on lambda expressions that encodes function
definition and application. Church and others were able to prove properties
of the lambda calculus that provide deep understanding of functions
and provide important insight into programming languages. In particular,
they showed the universality of the lambda calculus, the uniqueness of normal
forms, and the undecidablity of the equivalence of lambda expressions.
Topics
- substitution model of function application
- applicative order [call be value]
- normal order [call by need]
- lambda expressions
- < exp > &rarr variable
- application: < exp > &rarr (< exp > < exp >)
- abstraction: < exp > &rarr (lambda variable . < exp >)
- free and bound variables
- alpha conversion: (lambda x.E) is equivalent to (lambda y,E[x/y])
provided y does not appear free in E and y is not bound by a lambda
when substituted for x in E.
- beta reduction: ((lambda x.E) F) is equivalent to E[F/x], where
F is substituted for all free occurences of the variable x in E,
provided all free variables in F remain free when substituted for x
in E.
- Normal forms and the Church-Rosser theorem.
- Universality of the lambda calculus
- Church numerals and arithmetic using lambda calculus
- boolean logic, predicates, and conditional statements
using lambda calculus
- Data structures (lists, cons, car, cdr) using lambda calculus
- Recursion using lambda calculus
- (define fact (lambda (n) (if (= n 0) 1 (* n (fact (- n 1))))))
- (define g (lambda (f n) (if (= n 0) 1 (* n (f (- n 1))))))
- Y combinator:
(define Y (lambda (g)
((lambda (x) (g (x x))) (lambda (x) (g (x x))))))
- fixed point: (g (Y g)) = (Y g)
- (g (Y g) n)
Sample Functions
- church.scm - scheme implementation
of church numerals including successor, addition, and multiplication
functions.
- boolean.scm - lambda calculus
encoding of boolean logic, predicates, and conditional expressions.
- list.scm - lambda calculus encoding
of lists and list primitives cons, car, and cdr.
References
Exercises
- Study code implementing Church numerals and the implementation of
conditionals and lists in the lambda calculus.
- Trace through substitution of Y combinator (verify fixed point
property) and implementation of recursion in factorial.
- Sketch how to implement beta-reduction and alpha-conversion.
Created: May 22, 2008 (modified April 19, 2012) by jjohnson AT cs DOT drexel DOT DOT edu