Skip to content

Typed Lambda Calculus

by claude-opus-4-6
Learning objectives
  • Typed Lambda Calculus
Prerequisites
  • /mathematics/disciplines/type-theory/curricula/untyped-lambda-calculus.md
  • /mathematics/disciplines/logic/curricula/propositional-logic.md
Table of contents

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

The untyped lambda calculus begins with three operations [@barendregt_LambdaCalculus_1984]:

  1. Variables: xx, yy, zz, … — names that stand for values.
  2. Abstraction: λx.M\lambda x.\, M — a function that takes xx and returns MM. Read “the function of xx that gives MM.”
  3. Application: M  NM\; N — apply function MM to argument NN.

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

(λx.M)  N  β  M[N/x] (\lambda x.\, M)\; N \;\longrightarrow_\beta\; M[N/x]

Replace every occurrence of xx in MM with NN. 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: (λx.x  x)  (λx.x  x)(\lambda x.\, x\; x)\;(\lambda x.\, x\; x) 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_TypesProgrammingLanguages_2002]. Types are built from:

  • Base types: PP, QQ, … — atomic types representing basic domains (propositions, values, elements of an algebra).
  • Function types: ABA \to B — the type of functions that take an AA and return a BB.
  • Product types: A×BA \times B — the type of pairs (a,b)(a, b) where a:Aa : A and b:Bb : B.

A typing context Γ\Gamma is a list of variable-type assignments: x1:A1,  x2:A2,  x_1 : A_1, \; x_2 : A_2, \; \ldots

A typing judgment Γt:A\Gamma \vdash t : A states: “in context Γ\Gamma, term tt has type AA.”

Typing rules

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

Variable rule. If x:Ax : A appears in Γ\Gamma, then Γx:A\Gamma \vdash x : A.

Abstraction rule. If Γ,x:AM:B\Gamma, x : A \vdash M : B, then Γ(λx.M):AB\Gamma \vdash (\lambda x.\, M) : A \to B. To build a function from AA to BB, assume you have an xx of type AA and show the body MM has type BB.

Application rule. If ΓM:AB\Gamma \vdash M : A \to B and ΓN:A\Gamma \vdash N : A, then ΓM  N:B\Gamma \vdash M\; N : B. Apply a function to an argument of the right type.

Pairing rule. If ΓM:A\Gamma \vdash M : A and ΓN:B\Gamma \vdash N : B, then Γ(M,N):A×B\Gamma \vdash (M, N) : A \times B.

Projection rules. If ΓP:A×B\Gamma \vdash P : A \times B, then Γπ1(P):A\Gamma \vdash \pi_1(P) : A and Γπ2(P):B\Gamma \vdash \pi_2(P) : B.

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 Γ\Gamma does not break typing.
  • Exchange: the order of variables in Γ\Gamma does not matter.
  • Substitution: if ΓN:A\Gamma \vdash N : A and Γ,x:AM:B\Gamma, x : A \vdash M : B, then ΓM[N/x]:B\Gamma \vdash M[N/x] : B.
  • 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 [@sorensen_LecturesCurryHowardIsomorphism_2006]:

Logic Type Theory
Proposition Type
Proof of AA Term of type AA
ABA \wedge B A×BA \times B (product type)
ABA \Rightarrow B ABA \to B (function type)
Proof construction Term construction
Proof normalization Beta-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 PP:

(λx.x):PP \vdash (\lambda x.\, x) : P \to P

By the abstraction rule: assume x:Px : P, then x:Px : P by the variable rule, so λx.x\lambda x.\, x has type PPP \to P.

Define composition. Given f:ABf : A \to B and g:BCg : B \to C:

f:AB,  g:BC    (λx.g  (f  x)):AC f : A \to B, \; g : B \to C \;\vdash\; (\lambda x.\, g\;(f\;x)) : A \to C

Apply ff to xx to get a BB; apply gg to that BB to get a CC. The result is a function from AA to CC.

Common mistakes

  • Confusing untyped and typed. The untyped lambda calculus allows self-application (x  xx\;x); the typed calculus does not, because no type AA satisfies A=ABA = A \to B.
  • Forgetting that function types associate to the right. ABCA \to B \to C means A(BC)A \to (B \to C), a function that takes an AA and returns a function from BB to CC.
  • 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, PP).
  • Type constructors: \to (function) and ×\times (product).
  • Term constructors: variables, λ\lambda-abstraction, application, pairing, projection.
  • Typing rules: variable, abstraction, application, pairing, projection.
  • Computation rule: β\beta-reduction.

Relations

Authors
Cites
  • Lectures on the curry howard isomorphism
  • The lambda calculus its syntax and semantics
  • Types and programming languages
Date created
Requires
  • Mathematics disciplines type theory curricula untyped lambda calculus.md
  • Mathematics disciplines logic curricula propositional logic.md

Cite

@misc{claude-opus-4-62026-typed-lambda-calculus,
  author    = {claude-opus-4-6},
  title     = {Typed Lambda Calculus},
  year      = {2026},
  url       = {https://emsenn.net/library/math/domains/type-theory/texts/typed-lambda-calculus/},
  publisher = {emsenn.net},
  license   = {CC BY-SA 4.0}
}