Lambda Calculus
Table of Contents
A formal system for expressing computation through function
abstraction and application, introduced by Alonzo Church in
the 1930s. Equivalent in power to a Turing machine — any
computable problem can be expressed in it. The theoretical
foundation of functional programming and the origin of the
lambda keyword in Python, Haskell, Lisp, and most other
languages that support anonymous functions.
Related: Functional Programming Elixir
Three Constructs
Everything in lambda calculus is built from only three things:
| Construct | Notation | Meaning |
|---|---|---|
| Variable | x |
A placeholder name |
| Abstraction | λx.M |
A function with parameter x and body M |
| Application | M N |
Apply function M to argument N |
No types, no numbers, no booleans — just variables and functions.
Beta Reduction
The computation rule: applying a function substitutes the argument for the parameter in the body.
(λx.x) y → y identity function (λx.x + 1) 5 → 5 + 1 (with arithmetic notation) (λx.λy.x) a b → a constant function — ignores b
This substitution process — called beta reduction — is the only computation rule. All of computation reduces to this.
Church Encoding
Numbers, booleans, and data structures can all be represented as functions — demonstrating that functions alone are sufficient for universal computation:
# Church numerals — a number n is "apply f to x, n times" 0 = λf.λx.x 1 = λf.λx.f x 2 = λf.λx.f (f x) 3 = λf.λx.f (f (f x)) # Booleans true = λx.λy.x # select first argument false = λx.λy.y # select second argument # if-then-else follows naturally: if b then t else e = b t e
Influence on Programming Languages
# Python — lambda keyword directly from lambda calculus double = lambda x: x * 2 double(5) # 10 # Equivalent to: def double(x): return x * 2
-- Haskell — anonymous functions use lambda syntax double = \x -> x * 2 -- Partial application is lambda calculus currying made practical add = \x -> \y -> x + y add3 = add 3 -- a function waiting for the second argument add3 5 -- 8
# Elixir — anonymous functions double = fn x -> x * 2 end double.(5) # 10
Currying
Lambda calculus functions take exactly one argument. Multi- argument functions are expressed by returning functions — a technique called currying (after Haskell Curry):
λx.λy.x + y is a function that takes x
and returns a function that takes y
and returns x + y
(λx.λy.x + y) 3 → λy.3 + y (partially applied)
(λx.λy.x + y) 3 5 → 3 + 5 = 8
Currying is natively used in Haskell and Elixir; available
explicitly in Python via functools.partial.
Tips
- The lambda keyword in Python, Rust, Haskell, and most other
languages is a direct reference to lambda calculus —
lambda x: xis notation borrowed unchanged from Church - Currying explains why Haskell functions appear to take one argument at a time — all functions are curried by default
- Church encoding is worth understanding conceptually even if you never use it directly — it demonstrates that data and computation are equivalent, which underpins ideas like code-as-data in Lisp and macros in Elixir