Functional Programming - Lambda Calculus
Functional Programming - Lambda Calculus
Kaushiki Upadhyaya
Topics to be covered in the module
⩥ Introduction to lambda calculus
⩥ Functional Programming Concepts
⊳ First-class function values and higher-order functions
⊳ Extensive polymorphism
⊳ List types and operators
⊳ Structured function returns
⊳ Constructors (aggregates) for structured objects
⊳ Garbage collection
⩥ Evaluation order
⊳ Strictness
⊳ Lazy evaluation
⩥ Higher order Functions
⊳ Currying
⩥ I/O streams
⩥ Monads
Mathematical Notation
Ordered pair
λ-calculus
⩥ The λ-calculus is an elegant notation for working
with applications of functions to arguments
⩥ X2 −2⋅x+5
⩥ What is the value of this expression when x=2?
⩥ 22−2⋅2+5, which we can further reduce to get the
answer 5.
E → ID
E → λ ID . E
E→EE
E → (E)
x
λx.x
xy
λλx.y
λx.yz
foo λ bar . (foo (bar bar))
⩥ How to parse
xyz
Exp Exp
Exp z x Exp
x y y z
⩥ How to parse
λx.xy
Exp Exp
λ Exp Exp
x Exp
y
Exp Exp λ x Exp
x y x
⩥ E → E E is left associative
⊳ x y z is
■ (x y) z
⊳ w x y z is
■ ((w x) y) z
⩥ λ ID . E extends as far to the right as possible, starting with
the λ ID .
⊳ λ x . x y is
■ λ x . (x y)
⊳ λ x . λ x . x is
■ λ x. ( λ x . x)
⩥ (λ x . y) x is the same as λ x . y x
⊳ No!
⩥λa.λb.λc.abc
⊳ λ a . (λ b . (λ c . ((a b) c)))
⩥ E → λ ID . E is called an abstraction
⊳ The ID is the variable of the abstraction (also
metavariable)
⊳ E is called the body of the abstraction
⩥E→EE
⊳ This is called an application
⩥ x free in λ x . x y z?
⩥ y free in λ x . x y z?
⩥ x free in (λ x . (+ x 1)) x?
⩥ z free in λ x . λ y . λ z . z y x?
⩥ (λ x . x (λ y . x y z y) x) x y
⊳ (λ x . x (λ y . x y z y) x) x y
⩥ (λ x . λ y . x y) (λ z . x z)
⊳ (λ x . λ y . x y) (λ z . x z)
⩥ (λ x . x λ x . z x)
⊳ (λ x . x λ x . z x)