The simply typed lambda calculus (), a form
of
type theory
In mathematics and theoretical computer science, a type theory is the formal presentation of a specific type system. Type theory is the academic study of type systems.
Some type theories serve as alternatives to set theory as a foundation of ...
, is a
typed interpretation of the
lambda calculus
In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computability, computation based on function Abstraction (computer science), abstraction and function application, application using var ...
with only one
type constructor () that builds
function types. It is the canonical and simplest example of a typed lambda calculus. The simply typed lambda calculus was originally introduced by
Alonzo Church
Alonzo Church (June 14, 1903 – August 11, 1995) was an American computer scientist, mathematician, logician, and philosopher who made major contributions to mathematical logic and the foundations of theoretical computer science. He is bes ...
in 1940 as an attempt to avoid paradoxical use of the
untyped lambda calculus.
The term ''simple type'' is also used to refer to extensions of the simply typed lambda calculus with constructs such as
products,
coproducts or
natural number
In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positive in ...
s (
System T) or even full
recursion
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
(like
PCF). In contrast, systems that introduce
polymorphic types (like
System F) or
dependent types (like the
Logical Framework) are not considered ''simply typed''. The simple types, except for full recursion, are still considered ''simple'' because the
Church encodings of such structures can be done using only
and suitable type variables, while polymorphism and dependency cannot.
Syntax
In the 1930s Alonzo Church sought to use ''the logistic method'': his
lambda calculus
In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computability, computation based on function Abstraction (computer science), abstraction and function application, application using var ...
, as a formal language based on symbolic expressions, consisted of a denumerably infinite series of axioms and variables, but also a finite set of primitive symbols, denoting abstraction and scope, as well as four constants: negation, disjunction, universal quantification, and selection respectively; and also, a finite set of rules I to VI. This finite set of rules included rule V ''
modus ponens'' as well as IV and VI for substitution and generalization respectively. Rules I to III are known as alpha, beta, and eta conversion in the lambda calculus. Church sought to use English only as a syntax language (that is, a metamathematical language) for describing symbolic expressions with no interpretations.
In 1940 Church settled on a subscript notation for denoting the type in a symbolic expression. In his presentation, Church used only two base types:
for "the type of propositions" and
for "the type of individuals". The type
has no term constants, whereas
has one term constant. Frequently the calculus with only one base type, usually , is considered. The Greek letter subscripts , , etc. denote type variables; the parenthesized subscripted
denotes the function type . Church 1940 p.58 used 'arrow or ' to denote ''stands for'', or ''is an abbreviation for''.
By the 1970s stand-alone arrow notation was in use; for example in this article non-subscripted symbols
and
can range over types. The infinite number of axioms were then seen to be a consequence of applying rules I to VI to the types (see
Peano axioms). Informally, the ''function type''
refers to the type of functions that, given an input of type , produce an output of type .
By convention,
associates to the right:
is read as .
To define the types, a
set of ''base types'', , must first be defined. These are sometimes called ''atomic types'' or ''type constants''. With this fixed, the syntax of types is:
:
For example, , generates an infinite set of types starting with , , , , , , , ..., , ...
A set of ''term constants'' is also fixed for the base types. For example, it might be assumed that one of the base types is , and its term constants could be the natural numbers.
The syntax of the simply typed lambda calculus is essentially that of the lambda calculus itself. The term
denotes that the variable
is of type . The term syntax, in
Backus–Naur form
In computer science, Backus–Naur form (BNF, pronounced ), also known as Backus normal form, is a notation system for defining the Syntax (programming languages), syntax of Programming language, programming languages and other Formal language, for ...
, is ''variable reference'', ''abstractions'', ''application'', or ''constant'':
:
where
is a term constant. A variable reference
is ''bound'' if it is inside of an abstraction binding . A term is ''closed'' if there are no unbound variables.
In comparison, the syntax of untyped lambda calculus has no such typing or term constants:
:
Whereas in typed lambda calculus every ''abstraction'' (i.e. function) must specify the type of its argument.
Typing rules
To define the set of well-typed lambda terms of a given type, one defines a typing relation between terms and types. First, one introduces ''typing contexts'', or ''
typing environment In type theory, a typing environment (or typing context) represents the association between variable names and data types.
More formally, an environment \Gamma is a set or ordered list of pairs \langle x,\tau \rangle, usually written as x:\tau, whe ...
s''
, which are sets of typing assumptions. A ''typing assumption'' has the form , meaning variable
has type .
The ''typing relation''
indicates that
is a term of type
in context . In this case
is said to be ''well-typed'' (having type ). Instances of the typing relation are called ''typing judgments''. The validity of a typing judgment is shown by providing a ''typing derivation'', constructed using
typing rule
In type theory, a typing rule is an inference rule that describes how a type system assigns a type to a syntactic construction. These rules may be applied by the type system to determine if a program is well-typed and what type expressions ha ...
s (wherein the premises above the line allow us to derive the conclusion below the line). Simply typed lambda calculus uses these rules:
In words,
# If
has type
in the context, then
has type .
# Term constants have the appropriate base types.
# If, in a certain context with
having type ,
has type , then, in the same context without , has type .
# If, in a certain context,
has type , and
has type , then
has type .
Examples of closed terms, i.e. terms typable in the empty context, are:
* For every type , a term
(
identity function/I-combinator),
* For types , a term
(the K-combinator), and
* For types , a term
(the S-combinator).
These are the typed lambda calculus representations of the basic combinators of
combinatory logic.
Each type
is assigned an order, a number . For base types, ; for function types, . That is, the order of a type measures the depth of the most left-nested arrow. Hence:
:
:
Semantics
Intrinsic vs. extrinsic interpretations
Broadly speaking, there are two different ways of assigning meaning to the simply typed lambda calculus, as to typed languages more generally, variously called intrinsic vs. extrinsic, ontological vs. semantical, or Church-style vs. Curry-style.
An intrinsic semantics only assigns meaning to well-typed terms, or more precisely, assigns meaning directly to typing derivations. This has the effect that terms differing only by type annotations can nonetheless be assigned different meanings. For example, the identity term
on
integer
An integer is the number zero (0), a positive natural number (1, 2, 3, ...), or the negation of a positive natural number (−1, −2, −3, ...). The negations or additive inverses of the positive natural numbers are referred to as negative in ...
s and the identity term
on
booleans may mean different things. (The classic intended interpretations
are the identity function on integers and the identity function on boolean values.)
In contrast, an extrinsic semantics assigns meaning to terms regardless of typing, as they would be interpreted in an untyped language. In this view,
and
mean the same thing (i.e., the same thing as ).
The distinction between intrinsic and extrinsic semantics is sometimes associated with the presence or absence of annotations on lambda abstractions, but strictly speaking this usage is imprecise. It is possible to define an extrinsic semantics on annotated terms simply by ignoring the types (i.e., through
type erasure), as it is possible to give an intrinsic semantics on unannotated terms when the types can be deduced from context (i.e., through
type inference). The essential difference between intrinsic and extrinsic approaches is just whether the typing rules are viewed as defining the language, or as a formalism for verifying properties of a more primitive underlying language. Most of the different semantic interpretations discussed below can be seen through either an intrinsic or extrinsic perspective.
Equational theory
The simply typed lambda calculus (STLC) has the same
equational theory of βη-equivalence as
untyped lambda calculus, but subject to type restrictions. The equation for
beta reduction
: