Lambda calculus (also written λ-calculus) is a formal system for expressing computation using only three constructs: variables, function abstraction and function application. Introduced by Alonzo Church in the 1930s, it is the mathematical foundation of functional programming, and it is Turing complete: any computable function can be expressed in it.
In functional programming, lambda calculus explains why functions can be passed, returned and composed like ordinary values. Languages such as Haskell, OCaml, Lisp and Scheme are often described as lambda calculus with additions, such as data types, a type system and an efficient evaluation strategy.
The syntax of lambda calculus
The untyped lambda calculus has a grammar of only three forms, and every program is a term built from them. Despite this minimalism, numbers, booleans, data structures and recursion can all be encoded within the system.
The table below lists the three term forms with their notation and meaning.
| Term form | Notation | Meaning | Programming analogue |
|---|---|---|---|
| Variable | x | A name bound by an enclosing abstraction | A parameter reference |
| Abstraction | λx.M | A function with parameter x and body M | An anonymous function or lambda |
| Application | M N | Applying function M to argument N | A function call |
Two conventions keep terms readable. Application associates to the left, so f a b means (f a) b, and the body of an abstraction extends as far right as possible. Functions take exactly one argument, so multi-argument functions are expressed by currying: λx.λy.x is a function that takes x and returns another function that takes y.
A variable is bound when it lies inside an abstraction that introduces it, and free otherwise. In λx.x y, the variable x is bound and y is free. This distinction drives every rule of evaluation, because substitution must never accidentally capture a free variable.
Reduction rules and how evaluation works
Computation in lambda calculus is the repeated rewriting of terms by a small set of reduction rules until no further rule applies. The central rule, beta reduction, is simply function application performed by substitution.
| Rule | Transformation | Purpose |
|---|---|---|
| Alpha conversion | λx.x becomes λy.y | Renames bound variables to avoid capture |
| Beta reduction | (λx.M) N becomes M[x := N] | Performs function application |
| Eta conversion | λx.f x becomes f if x is not free in f | Expresses function extensionality |
A term with no remaining beta redex is in normal form, which plays the role of a final result. Not every term has one: the term (λx.x x)(λx.x x), usually called omega, reduces to itself forever, the lambda calculus equivalent of an infinite loop.
The Church-Rosser theorem guarantees that the order of reductions cannot produce two different normal forms: if a normal form exists, it is unique. Order still matters for termination, however, which is why evaluation strategies are central to language design.
| Strategy | What is reduced first | Finds normal form if one exists | Used by |
|---|---|---|---|
| Normal order | Leftmost outermost redex | Yes | Theoretical reference strategy |
| Call by name | Outer function, arguments unevaluated | Yes, for weak head normal form | Algol 60 parameters |
| Call by need | Like call by name, with sharing | Yes, for weak head normal form | Haskell through lazy evaluation |
| Call by value | Arguments before the function body | No, may diverge | OCaml, Scheme, most languages |
Encoding data and recursion
Because pure lambda calculus has no built-in values, data is represented by Church encodings, in which each value is a function that captures how it is used. A boolean chooses between two alternatives, and a natural number applies a function a given number of times.
- Church booleans:
trueisλt.λf.tandfalseisλt.λf.f, so a conditional is plain application. - Church numerals:
2isλf.λx.f (f x), and addition composes repeated applications. - Pairs and lists: a pair is
λa.λb.λs.s a b, which a selector function takes apart. - Recursion: the Y combinator
λf.(λx.f (x x))(λx.f (x x))gives an anonymous function access to itself.
Under call-by-value evaluation the Y combinator diverges, so strict languages use the variant called the Z combinator, which delays self-application behind an extra abstraction. Real compilers, of course, provide recursion and primitive data directly, because Church encodings are elegant but inefficient.
Typed lambda calculi and their role in language design
Typed variants of lambda calculus restrict which terms are allowed in order to rule out errors and, in some systems, guarantee termination. They form the basis of the type systems of modern functional languages and of proof assistants.
| Variant | Key feature | Termination guaranteed | Practical influence |
|---|---|---|---|
| Untyped lambda calculus | No types, full Turing completeness | No | Lisp and Scheme semantics |
| Simply typed lambda calculus | Function types only | Yes | Foundations of type checking |
| System F | Parametric polymorphism | Yes | Generics in Haskell and ML |
| Hindley-Milner | Polymorphism with type inference | Yes, without recursion | ML, OCaml, Haskell inference |
| Calculus of constructions | Dependent types | Yes | Coq and related proof assistants |
The Curry-Howard correspondence connects typed lambda calculi with logic: types correspond to propositions and well-typed terms to proofs. This link explains why proof assistants can verify mathematics by type checking programs.
Lambda calculus compared with other models of computation
Lambda calculus and the Turing machine are equivalent in power, a result connected to the Church-Turing thesis, but they describe computation from opposite directions. The Turing machine models a mutable tape processed step by step, while lambda calculus models computation as the evaluation of expressions, without state or assignment.
That difference maps directly onto programming paradigms. Imperative languages follow the machine model, while functional languages follow the expression model, which is why concepts such as referential transparency, pure functions, closures and higher-order functions feel natural in functional code. A common misconception is that lambda calculus is only historical theory; in fact, many compilers translate source programs into a lambda-based intermediate language, such as the Core language in GHC, before optimizing them.
The idea in brief
Lambda calculus is a tiny language made only of functions. It has no numbers, no loops and no variables that change. You can only define a function and apply it to something.
Surprisingly, that is enough to compute anything a computer can compute. It works like a recipe system in which every ingredient is itself a recipe. Functional programming languages are built on this idea, which is why they treat functions as ordinary values.
A practical scenario
A small compiler team is building a domain-specific language for pricing rules in an insurance system. Instead of designing semantics from scratch, the team defines a core language based on the simply typed lambda calculus, extended with numbers, records and conditionals. Every user-facing feature, such as named rules and default parameters, is translated into this core before evaluation.
Because the core is small, the team writes an interpreter of about 600 lines and a type checker that guarantees every pricing rule terminates. When an analyst writes a rule that applies a percentage to a text field, the type checker rejects it before deployment. The result is a language whose behavior is precisely defined, easy to test, and free of infinite loops in production.