The simply typed lambda calculus (
), a form
of
type theory
In mathematics, logic, and computer science, a type theory is the formal presentation of a specific type system, and in general type theory is the academic study of type systems. Some type theories serve as alternatives to set theory as a fou ...
, is a
typed interpretation of the
lambda calculus with only one
type constructor
In the area of mathematical logic and computer science known as type theory, a type constructor is a feature of a typed formal language that builds new types from old ones. Basic types are considered to be built using nullary type constructors. S ...
(
) that builds
function type In computer science and mathematical logic, a function type (or arrow type or exponential) is the type of a variable or parameter to which a function has or can be assigned, or an argument or result type of a higher-order function taking or re ...
s. 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 mathematician, computer scientist, logician, philosopher, professor and editor who made major contributions to mathematical logic and the foundations of theoretical computer scien ...
in 1940 as an attempt to avoid paradoxical use of the
untyped lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation tha ...
.
The term ''simple type'' is also used to refer extensions of the simply typed lambda calculus such as
products
Product may refer to:
Business
* Product (business), an item that serves as a solution to a specific consumer problem.
* Product (project management), a deliverable or set of deliverables that contribute to a business solution
Mathematics
* Produ ...
,
coproduct
In category theory, the coproduct, or categorical sum, is a construction which includes as examples the disjoint union of sets and of topological spaces, the free product of groups, and the direct sum of modules and vector spaces. The coproduc ...
s or
natural number
In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country").
Numbers used for counting are called ''cardinal ...
s (
System T) or even full
recursion
Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathemati ...
(like
PCF). In contrast, systems which introduce
polymorphic types (like
System F
System F (also polymorphic lambda calculus or second-order lambda calculus) is a typed lambda calculus that introduces, to simply typed lambda calculus, a mechanism of universal quantification over types. System F formalizes parametric polymorph ...
) or
dependent type
In computer science and logic, a dependent type is a type whose definition depends on a value. It is an overlapping feature of type theory and type systems. In intuitionistic type theory, dependent types are used to encode logic's quantifiers lik ...
s (like the
Logical Framework) are not considered ''simply typed''. The simple types, except for full recursion, are still considered ''simple'' because the
Church encoding
In mathematics, Church encoding is a means of representing data and operators in the lambda calculus. The Church numerals are a representation of the natural numbers using lambda notation. The method is named for Alonzo Church, who first encoded da ...
s of such structures can be done using only
and suitable type variables, while polymorphism and dependency cannot.
Syntax
In this article, the symbols
and
are used to range over types. 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 assumed that a base type , and the term constants could be the natural numbers. In the original 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 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
BNF, is then:
:
where
is a term constant.
That is, ''variable reference'', ''abstractions'', ''application'', and ''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, we will define a typing relation between terms and types. First, we introduce ''typing contexts'' or ''
typing environments''
, which are sets of typing assumptions. A ''typing assumption'' has the form
, meaning
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 judgements''. The validity of a typing judgement is shown by providing a ''typing derivation'', constructed using
typing rules (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, we know that
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 integers 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 a extrinsic semantics on annotated terms simply by ignoring the types (''i.e.'', through
type erasure In programming languages, type erasure is the load-time process by which explicit type annotations are removed from a program, before it is executed at run-time. Operational semantics that do not require programs to be accompanied by types are c ...
), as it is possible to give a intrinsic semantics on unannotated terms when the types can be deduced from context (''i.e.'', through
type inference
Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistic ...
). 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 has the same
equational theory
Universal algebra (sometimes called general algebra) is the field of mathematics that studies algebraic structures themselves, not examples ("models") of algebraic structures.
For instance, rather than take particular groups as the object of stud ...
of βη-equivalence as
untyped lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation tha ...
, but subject to type restrictions. The equation for
beta reduction
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation tha ...
: