Lambda calculus

Also known as: λ-calculus

On this page 7

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 formNotationMeaningProgramming analogue
VariablexA name bound by an enclosing abstractionA parameter reference
Abstractionλx.MA function with parameter x and body MAn anonymous function or lambda
ApplicationM NApplying function M to argument NA function call
The three kinds of lambda terms

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.

RuleTransformationPurpose
Alpha conversionλx.x becomes λy.yRenames 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 fExpresses function extensionality
Core conversion and reduction rules

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.

StrategyWhat is reduced firstFinds normal form if one existsUsed by
Normal orderLeftmost outermost redexYesTheoretical reference strategy
Call by nameOuter function, arguments unevaluatedYes, for weak head normal formAlgol 60 parameters
Call by needLike call by name, with sharingYes, for weak head normal formHaskell through lazy evaluation
Call by valueArguments before the function bodyNo, may divergeOCaml, Scheme, most languages
Evaluation strategies and their language counterparts

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: true is λt.λf.t and false is λt.λf.f, so a conditional is plain application.
  • Church numerals: 2 is λ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.

VariantKey featureTermination guaranteedPractical influence
Untyped lambda calculusNo types, full Turing completenessNoLisp and Scheme semantics
Simply typed lambda calculusFunction types onlyYesFoundations of type checking
System FParametric polymorphismYesGenerics in Haskell and ML
Hindley-MilnerPolymorphism with type inferenceYes, without recursionML, OCaml, Haskell inference
Calculus of constructionsDependent typesYesCoq and related proof assistants
Major lambda calculus variants

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.