Entry conditions

Use typed lambda calculus when you need:

  • A formal language for defining functions, applying them to arguments, and composing them.
  • A type system that prevents ill-formed combinations (applying a number to a number, for instance).
  • A bridge between logic and computation, where types correspond to propositions and terms correspond to proofs.

The untyped lambda calculus

Lambda calculus begins with three operations (Barendregt, 1984):

  1. Variables: , , , … — names that stand for values.
  2. Abstraction: — a function that takes and returns . Read “the function of that gives .”
  3. Application: — apply function to argument .

Everything is built from these three forms. The central computation rule is beta-reduction:

Replace every occurrence of in with . This is function evaluation.

The untyped lambda calculus is expressive enough to encode arithmetic, recursion, and data structures. It is also expressive enough to produce nonsense: reduces to itself forever.

Adding types

The simply typed lambda calculus (STLC) assigns a type to every term, ruling out self-application and non-termination (Pierce, 2002). Types are built from:

  • Base types: , , … — atomic types representing basic domains (propositions, values, elements of an algebra).
  • Function types: — the type of functions that take an and return a .
  • Product types: — the type of pairs where and .

A typing context is a list of variable-type assignments:

A typing judgment states: “in context , term has type .”

Typing rules

The STLC has a small set of rules that determine when a typing judgment holds:

Variable rule. If appears in , then .

Abstraction rule. If , then . To build a function from to , assume you have an of type and show the body has type .

Application rule. If and , then . Apply a function to an argument of the right type.

Pairing rule. If and , then .

Projection rules. If , then and .

These rules ensure that every well-typed term reduces to a value and that reduction preserves types (subject reduction).

Structural properties

Well-typed terms satisfy:

  • Weakening: adding unused variables to does not break typing.
  • Exchange: the order of variables in does not matter.
  • Substitution: if and , then .
  • Strong normalization: every sequence of reductions terminates. There are no infinite loops in the simply typed calculus.

The Curry-Howard correspondence

There is a precise correspondence between the simply typed lambda calculus and intuitionistic logic (Sørensen & Urzyczyn, 2006):

LogicType Theory
PropositionType
Proof of Term of type
(product type)
(function type)
Proof constructionTerm construction
Proof normalizationBeta-reduction

A type is inhabited (has a term of that type) exactly when the corresponding proposition is provable in intuitionistic logic. This is not a metaphor — it is a formal isomorphism. Proofs ARE programs; propositions ARE types. This is known as the Curry-Howard correspondence.

Worked example

Define the identity function on type :

By the abstraction rule: assume , then by the variable rule, so has type .

Define composition. Given and :

Apply to to get a ; apply to that to get a . The result is a function from to .

Common mistakes

  • Confusing untyped and typed. The untyped lambda calculus allows self-application (); the typed calculus does not, because no type satisfies .
  • Forgetting that function types associate to the right. means , a function that takes an and returns a function from to .
  • Treating the Curry-Howard correspondence as approximate. It is an exact structural correspondence between proof systems and type systems, not an analogy.

Minimal data

  • A set of base types (at minimum, ).
  • Type constructors: (function) and (product).
  • Term constructors: variables, -abstraction, application, pairing, projection.
  • Typing rules: variable, abstraction, application, pairing, projection.
  • Computation rule: -reduction.
Barendregt, H. P. (1984). The Lambda Calculus: Its Syntax and Semantics (Revised). North-Holland.
Pierce, B. C. (2002). Types and Programming Languages. MIT Press.
Sørensen, M. H., & Urzyczyn, P. (2006). Lectures on the Curry-Howard Isomorphism. Elsevier.