Professional Documents
Culture Documents
08 Lambda Calculus
08 Lambda Calculus
Adam Doupé
Arizona State University
http://adamdoupe.com
Lambda Calculus
• Language to express function application
– Ability to define anonymous functions
– Ability to "apply" functions
• Functional programming derives from
lambda calculus
– ML
– Haskell
– F#
– Clojure
Adam Doupé, Principles of Programming Languages 2
History
• Frege in 1893 studied the use of functions in logic
• Schönfinkel, in the 1920s, studied how combinators, a
specific type of function, could be applied to formal logic
• Church introduced lambda calculus in the 1930s
• Original system was shown to be logically inconsistent
in 1935 by Kleene and Rosser
• In 1936, Church published the lambda calculus that is
relevant to computation
• Refined further
– Type systems, …
Adapted from Jesse Alama:
http://plato.stanford.edu/entries/lambda-calculus/#BriHisLCal
E → ID
E → λ ID . E
E→EE
E → (E)
x
λx.x
xy
λλx.y
λx.yz
foo λ bar . (foo (bar baz))
Adam Doupé, Principles of Programming Languages 5
Ambiguous Syntax
• How to parse
xyz
Exp Exp
Exp z x Exp
x y y z
λ Exp Exp
x Exp
y
Exp Exp λ x Exp
x y x
• if c a b
• if T a b = a
• if F a b = b
• if = (λ a . a)
Adam Doupé, Principles of Programming Languages 41
Examples
• if T a b
– (λ a . a) T a b
–Tab
–a
• if F a b
– (λ a . a) F a b
–Fab
–b
int fact(int n)
{
if (n == 0)
{
return 1;
}
return n * fact(n-1);
}
PRINCIPLES OF
PROGRAMMING LANGUAGES
56