Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism = propositions as types +programs as proofs +relation type theory/category theory

logiccategory theorytype theory
trueterminal object/(-2)-truncated objecth-level 0-type/unit type
falseinitial objectempty type
proposition(-1)-truncated objecth-proposition, mere proposition
proofgeneralized elementprogram
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
cut elimination for implicationcounit for hom-tensor adjunctionbeta reduction
introduction rule for implicationunit for hom-tensor adjunctioneta conversion
conjunctionproductproduct type
disjunctioncoproduct ((-1)-truncation of)sum type (bracket type of)
implicationinternal homfunction type
negationinternal hom into initial objectfunction type into empty type
universal quantificationdependent productdependent product type
existential quantificationdependent sum ((-1)-truncation of)dependent sum type (bracket type of)
equivalencepath space objectidentity type
equivalence classquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
completely presented setdiscrete object/0-truncated objecth-level 2-type/preset/h-set
setinternal 0-groupoidBishop set/setoid
universeobject classifiertype of types
modalityclosure operator, (idemponent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels


The λ-calculus


The lambda calculus is:

It comes in both typed and untyped (or, more correctly, single-typed) versions.


Abstraction and application

The basic constructs of lambda calculus are lambda abstractions and applications. If tt is an expression of some sort involving a free variable xx (possibly vacuously), then the lambda abstraction

λx.t \lambda x. t

is intended to represent the function which takes one input and returns the result of substituting that input for xx in tt. Thus, for instance, (λx.(x+1))(\lambda x. (x+1)) is the function which adds one to its argument. Lambda expressions are often convenient, even outside lambda calculus proper, for referring to a function without giving it a name.

Application is how we “undo” abstraction, by applying a function to an argument. The application of the function ff to the argument tt is generally denoted simply by ftf t. Applications can be parenthesized, so for instance f(t)f(t) and (f)t(f)t and (ft)(f t) all denote the same thing as ftf t.

Application is generally considered to associate to the left. Thus uvwu v w denotes the application of uu to vv, followed by application of the result (assumed to again be a function) to ww. This allows the representation of functions of multiple variables in terms of functions of one variable via “currying” (named for Haskell Curry, although it was invented by Moses Schönfinkel): after being applied to the first argument, we return a function which, applied to the next argument, returns a function which, when applied to the next argument, … , returns a value. For instance, the “addition” function of two variables can be denoted (λx.(λy.x+y))(\lambda x. (\lambda y. x+y)): when applied to an argument xx, it returns a function which, when applied to an argument yy, returns x+yx+y. This is so common that it is generally abbreviated (λxy.x+y)(\lambda x y. x+y).

Evaluation and Reduction

Evaluation or reduction is the process of “computing” the “value” of a lambda term. The most basic operation is called beta reduction and consists in taking a lambda abstraction at its word about what it is supposed to do when applied to an input. For instance, the application (λx.x+1)3(\lambda x. x+1) 3 reduces to 3+13+1 (and thereby, presuming appropriate rules for ++, to 44). Terms which can be connected by a zigzag of beta reductions (in either direction) are said to be beta-equivalent.

Another basic operation often assumed in the lambda calculus is eta reduction/expansion, which consists of identifying a function, ff with the lambda abstraction (λx.fx)(\lambda x. f x) which does nothing other than apply ff to its argument. (It is called “reduction” or “expansion” depending on which “direction” it goes in, from (λx.fx)(\lambda x. f x) to ff or vice versa.)

A more basic operation than either of these, which is often not even mentioned at all, is alpha equivalence; this consists of the renaming of bound variables, e.g. (λx.fx)(λy.fy)(\lambda x. f x) \to (\lambda y. f y).

More complicated systems that build on the lambda calculus, such as various type theories?, will often have other rules of evaluation as well.

In good situations, lambda-calculus reduction is confluent and terminating (the Church-Rosser theorem), so that every term has a normal form?, and two terms are equivalent precisely when they have the same normal form.


Pure lambda calculus

In the pure “untyped” lambda calculus, there is only one kind of variable and one kind of term, and the only construction used to form expressions is application of a function ff to an argument tt, generally denoted simply ftf t. In particular, all variables and terms “represent functions”, and can be applied to any other variable or term.

From the point of view of type theory, it is more appropriate to call this “single-typed” or “unityped” lambda-calculus rather than “untyped” — there is a single type which all terms belong to.

As an example of the sort of freedom this allows, any term can always be applied to itself. We can then form the term λx.xx\lambda x. x x which applies its argument to itself. The self-application of this term:

(λx.xx)(λx.xx) (\lambda x. x x) (\lambda x. x x)

is a classic example of a term which admits an infinite sequence of beta-reductions (each of which leads back to itself).

In pure untyped lambda calculus, we can define natural numbers using the Church numerals?: the number nn is represented by the operation of nn-fold iteration. Thus for instance we have 2=λf.(λx.f(fx))2 = \lambda f. (\lambda x.f (f x)), the function which takes a function ff as input and returns a function that applies ff twice. Similarly 1=λf.(λx.fx)1 = \lambda f. (\lambda x.f x) is the identity on functions, while 0=λf.(λx.x)0 = \lambda f. (\lambda x . x) takes any function ff to the identity function (the 0th iterate of ff). We can then construct (very inefficiently) all of arithmetic, and prove that the arithmetic functions expressible by lambda terms are exactly the same as those computable by Turing machines or (total) recursive functions.

The most natural sort of model of pure lambda calculus is a set or other object DD which is equivalent to its own exponential D DD^D. Of course there are no nontrivial such models in sets, but they do exist in other categories, such as domains. It is worth remarking that a necessary condition on such DD is that every term f:D Df \colon D^D have a fixed-point; see fixed-point combinator.

Simply typed lambda calculus

In simply typed lambda calculus, each variable and term has a type, and we can only form the application ftf t if tt is of some type AA while ff is of a function type AB=B AA \to B = B^A whose domain is AA; the type of ftf t is then BB. Similarly, if xx is a variable of type AA and tt is a term of type BB involving xx, then λx.t\lambda x. t has type ABA\to B.

Without some further type and term constructors, there is not much that can be done, but if we add a natural numbers object (that is, a type NN with constants 00 of type NN and ss of type NNN\to N, along with a “definition-by-recursion” operator), then we can express many recursive functions. (We cannot by this means express all computable functions, although we can go beyond primitive recursive function?s; for instance we can define the Ackermann function?. One way to increase the expressiveness to all partial recursive functions is to add a fixpoint? combinator?, or an unbounded search operator).

Simply typed lambda calculus is the natural internal language of cartesian closed categories. This means that

  • Every cartesian closed category gives rise to a simply typed lambda calculus whose basic types are its objects, and whose basic terms are its morphisms, while

  • Every simply typed lambda calculus “generates” a cartesian closed category whose objects are its types and whose morphisms are its equivalence classes of terms.

These two operations are adjoint in an appropriate sense.

Functional programming

Most functional programming languages, such as Lisp, ML, and Haskell, are at least loosely based on lambda calculus.


Please add…

Revised on August 13, 2012 00:20:33 by Mike Shulman (