HOME

TheInfoList



OR:

The simply typed lambda calculus (\lambda^\to), 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 ...
(\to) 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 \to and suitable type variables, while polymorphism and dependency cannot.


Syntax

In this article, the symbols \sigma and \tau are used to range over types. Informally, the ''function type'' \sigma \to \tau refers to the type of functions that, given an input of type \sigma, produce an output of type \tau. By convention, \to associates to the right: \sigma\to\tau\to\rho is read as \sigma\to(\tau\to\rho). To define the types, a set of ''base types'', B, must first be defined. These are sometimes called ''atomic types'' or ''type constants''. With this fixed, the syntax of types is: :\tau ::= \tau \to \tau \mid T \quad \mathrm \quad T \in B. For example, B = \, generates an infinite set of types starting with a,b,a \to a,a \to b,b\to b,b\to a, a \to (a \to a),\ldots,(b\to a) \to (a\to b), \ldots 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: o for "the type of propositions" and \iota for "the type of individuals". The type o has no term constants, whereas \iota has one term constant. Frequently the calculus with only one base type, usually o, is considered. The syntax of the simply typed lambda calculus is essentially that of the lambda calculus itself. The term x\mathbin\tau denotes that the variable x is of type \tau. The term syntax, in BNF, is then: :e ::= x \mid \lambda x\mathbin\tau.e \mid e \, e \mid c where c is a term constant. That is, ''variable reference'', ''abstractions'', ''application'', and ''constant''. A variable reference x is ''bound'' if it is inside of an abstraction binding x. 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: :e ::= x \mid \lambda x.e \mid e \, e 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'' \Gamma,\Delta,\dots, which are sets of typing assumptions. A ''typing assumption'' has the form x\mathbin\sigma, meaning x has type \sigma. The ''typing relation'' \Gamma\vdash e\mathbin\sigma indicates that e is a term of type \sigma in context \Gamma. In this case e is said to be ''well-typed'' (having type \sigma). 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 x has type \sigma in the context, we know that x has type \sigma. # Term constants have the appropriate base types. # If, in a certain context with x having type \sigma, e has type \tau, then, in the same context without x, \lambda x\mathbin\sigma.~e has type \sigma \to \tau. # If, in a certain context, e_1 has type \sigma \to \tau, and e_2 has type \sigma, then e_1~e_2 has type \tau. Examples of closed terms, ''i.e.'' terms typable in the empty context, are: *For every type \tau, a term \lambda x\mathbin\tau.x\mathbin\tau\to\tau (identity function/I-combinator), *For types \sigma,\tau, a term \lambda x\mathbin\sigma.\lambda y\mathbin\tau.x\mathbin\sigma \to \tau \to \sigma (the K-combinator), and *For types \tau,\tau',\tau'', a term \lambda x\mathbin\tau\to\tau'\to\tau''.\lambda y\mathbin\tau\to\tau'.\lambda z\mathbin\tau.x z (y z) : (\tau\to\tau'\to\tau'')\to(\tau\to\tau')\to\tau\to\tau'' (the S-combinator). These are the typed lambda calculus representations of the basic combinators of combinatory logic. Each type \tau is assigned an order, a number o(\tau). For base types, o(T)=0; for function types, o(\sigma\to\tau)=\mbox(o(\sigma)+1,o(\tau)). That is, the order of a type measures the depth of the most left-nested arrow. Hence: : o(\iota \to \iota \to \iota) = 1 : o((\iota \to \iota) \to \iota) = 2


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 \lambda x\mathbin\mathtt.~x on integers and the identity term \lambda x\mathbin\mathtt.~x 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, \lambda x\mathbin\mathtt.~x and \lambda x\mathbin\mathtt.~x mean the same thing (''i.e.'', the same thing as \lambda x.~x). 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 ...
:(\lambda x\mathbin\sigma.~t)\,u =_ t :=u/math> holds in context \Gamma whenever \Gamma,x\mathbin\sigma \vdash t\mathbin\tau and \Gamma\vdash u\mathbin\sigma, while the equation for
eta 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 ...
:\lambda x\mathbin\sigma.~t\,x =_\eta t holds whenever \Gamma\vdash t\!:\sigma \to \tau and x does not appear free in t.


Operational semantics

Likewise, the
operational semantics Operational semantics is a category of formal programming language semantics in which certain desired properties of a program, such as correctness, safety or security, are verified by constructing proofs from logical statements about its execut ...
of simply typed lambda calculus can be fixed as for the untyped lambda calculus, using
call by name In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
,
call by value In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
, or other evaluation strategies. As for any typed language,
type safety In computer science, type safety and type soundness are the extent to which a programming language discourages or prevents type errors. Type safety is sometimes alternatively considered to be a property of facilities of a computer language; that i ...
is a fundamental property of all of these evaluation strategies. Additionally, the strong normalization property described below implies that any evaluation strategy will terminate on all simply typed terms.


Categorical semantics

The simply typed lambda calculus (with \beta\eta-equivalence) is the
internal language __NOTOC__ Categorical logic is the branch of mathematics in which tools and concepts from category theory are applied to the study of mathematical logic. It is also notable for its connections to theoretical computer science. In broad terms, categ ...
of Cartesian closed categories (CCCs), as was first observed by
Joachim Lambek Joachim "Jim" Lambek (5 December 1922 – 23 June 2014) was a German-born Canadian mathematician. He was Peter Redpath Emeritus Professor of Pure Mathematics at McGill University, where he earned his PhD degree in 1950 with Hans Zassenhaus a ...
. Given any specific CCC, the basic types of the corresponding lambda calculus are just the objects, and the terms are the morphisms. Conversely, every simply typed lambda calculus gives a CCC whose objects are the types, and morphisms are equivalence classes of terms. To make the correspondence clear, a
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 ...
for the Cartesian product is typically added to the above. To preserve the categoricity of the Cartesian product, one adds typing rules for ''pairing'', ''projection'', and a ''unit term''. Given two terms s\mathbin\sigma and t\mathbin\tau, the term (s,t) has type \sigma\times\tau. Likewise, if one has a term u\mathbin\tau_1\times\tau_2, then there are terms \pi_1(u)\mathbin\tau_1 and \pi_2(u)\mathbin\tau_2 where the \pi_i correspond to the projections of the Cartesian product. The ''unit term'', of type 1, is written as () and vocalized as 'nil', is the
final object In category theory, a branch of mathematics, an initial object of a category is an object in such that for every object in , there exists precisely one morphism . The dual notion is that of a terminal object (also called terminal element): ...
. The equational theory is extended likewise, so that one has :\pi_1(s\mathbin\sigma,t\mathbin\tau) = s\mathbin\sigma :\pi_2(s\mathbin\sigma,t\mathbin\tau) = t\mathbin\tau :(\pi_1(u\mathbin\sigma\times\tau) , \pi_2(u\mathbin\sigma\times\tau)) =u\mathbin\sigma\times\tau :t\mathbin1 = () This last is read as "''if t has type 1, then it reduces to nil''". The above can then be turned into a category by taking the types as the objects. The morphisms \sigma\to\tau are equivalence classes of pairs (x\mathbin\sigma, t\mathbin\tau) where ''x'' is a variable (of type \sigma) and ''t'' is a term (of type \tau), having no free variables in it, except for (optionally) ''x''. Closure is obtained from currying and application, as usual. More precisely, there exist
functor In mathematics, specifically category theory, a functor is a mapping between categories. Functors were first considered in algebraic topology, where algebraic objects (such as the fundamental group) are associated to topological spaces, and m ...
s between the category of Cartesian closed categories, and the category of simply-typed lambda theories. It is common to extend this case to closed symmetric monoidal categories by using a
linear type system Substructural type systems are a family of type systems analogous to substructural logics where one or more of the structural rules are absent or only allowed under controlled circumstances. Such systems are useful for constraining access to sy ...
. The reason for this is that the CCC is a special case of the closed symmetric monoidal category, which is typically taken to be the
category of sets In the mathematical field of category theory, the category of sets, denoted as Set, is the category whose objects are sets. The arrows or morphisms between sets ''A'' and ''B'' are the total functions from ''A'' to ''B'', and the composition o ...
. This is fine for laying the foundations of
set theory Set theory is the branch of mathematical logic that studies sets, which can be informally described as collections of objects. Although objects of any kind can be collected into a set, set theory, as a branch of mathematics, is mostly conce ...
, but the more general
topos In mathematics, a topos (, ; plural topoi or , or toposes) is a category that behaves like the category of sheaves of sets on a topological space (or more generally: on a site). Topoi behave much like the category of sets and possess a notio ...
seems to provide a superior foundation.


Proof-theoretic semantics

The simply typed lambda calculus is closely related to the implicational fragment of propositional
intuitionistic logic Intuitionistic logic, sometimes more generally called constructive logic, refers to systems of symbolic logic that differ from the systems used for classical logic by more closely mirroring the notion of constructive proof. In particular, systems ...
, i.e.,
minimal logic Minimal logic, or minimal calculus, is a symbolic logic system originally developed by Ingebrigt Johansson. It is an intuitionistic and paraconsistent logic, that rejects both the law of the excluded middle as well as the principle of explosion ...
, via the Curry–Howard isomorphism: terms correspond precisely to proofs in
natural deduction In logic and proof theory, natural deduction is a kind of proof calculus in which logical reasoning is expressed by inference rules closely related to the "natural" way of reasoning. This contrasts with Hilbert-style systems, which instead use ax ...
, and inhabited types are exactly the tautologies of minimal logic.


Alternative syntaxes

The presentation given above is not the only way of defining the syntax of the simply typed lambda calculus. One alternative is to remove type annotations entirely (so that the syntax is identical to the untyped lambda calculus), while ensuring that terms are well-typed via Hindley–Milner type inference. The inference algorithm is terminating, sound, and complete: whenever a term is typable, the algorithm computes its type. More precisely, it computes the term's
principal type In type theory, a type system is said to have the principal type property if, given a term and an environment, there exists a principal type for this term in this environment, i.e. a type such that all other types for this term in this environment a ...
, since often an unannotated term (such as \lambda x.~x) may have more than one type (\mathtt \to \mathtt, \mathtt \to \mathtt, etc., which are all instances of the principal type \alpha \to \alpha). Another alternative presentation of simply typed lambda calculus is based on bidirectional type checking, which requires more type annotations than Hindley–Milner inference but is easier to describe. The
type system In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progr ...
is divided into two judgments, representing both ''checking'' and ''synthesis'', written \Gamma \vdash e \Leftarrow \tau and \Gamma \vdash e \Rightarrow \tau respectively. Operationally, the three components \Gamma, e, and \tau are all ''inputs'' to the checking judgment \Gamma \vdash e \Leftarrow \tau, whereas the synthesis judgment \Gamma \vdash e \Rightarrow \tau only takes \Gamma and e as inputs, producing the type \tau as output. These judgments are derived via the following rules: Observe that rules €“ are nearly identical to rules (1)–(4) above, except for the careful choice of checking or synthesis judgments. These choices can be explained like so: # If x\mathbin\sigma is in the context, we can synthesize type \sigma for x. # The types of term constants are fixed and can be synthesized. # To check that \lambda x.~e has type \sigma \to \tau in some context, we extend the context with x\mathbin\sigma and check that e has type \tau. # If e_1 synthesizes type \sigma \to \tau (in some context), and e_2 checks against type \sigma (in the same context), then e_1~e_2 synthesizes type \tau. Observe that the rules for synthesis are read top-to-bottom, whereas the rules for checking are read bottom-to-top. Note in particular that we do not need any annotation on the lambda abstraction in rule because the type of the bound variable can be deduced from the type at which we check the function. Finally, we explain rules and as follows:
  1. To check that e has type \tau, it suffices to synthesize type \tau.
  2. If e checks against type \tau, then the explicitly annotated term (e\mathbin\tau) synthesizes \tau.
Because of these last two rules coercing between synthesis and checking, it is easy to see that any well-typed but unannotated term can be checked in the bidirectional system, so long as we insert "enough" type annotations. And in fact, annotations are needed only at β-redexes.


General observations

Given the standard semantics, the simply typed lambda calculus is strongly normalizing: that is, well-typed terms always reduce to a value, i.e., a \lambda abstraction. This is because recursion is not allowed by the typing rules: it is impossible to find types for
fixed-point combinator In mathematics and computer science in general, a '' fixed point'' of a function is a value that is mapped to itself by the function. In combinatory logic for computer science, a fixed-point combinator (or fixpoint combinator) is a higher-order ...
s and the looping term \Omega = (\lambda x.~x~x) (\lambda x.~x~x). Recursion can be added to the language by either having a special operator \mathtt_\alphaof type (\alpha \to \alpha) \to \alpha or adding general
recursive type In computer programming languages, a recursive data type (also known as a recursively-defined, inductively-defined or inductive data type) is a data type for values that may contain other values of the same type. Data of recursive types are usuall ...
s, though both eliminate strong normalization. Since it is strongly normalising, it is decidable whether or not a simply typed lambda calculus program halts: in fact, it ''always'' halts. We can therefore conclude that the language is ''not''
Turing complete Alan Mathison Turing (; 23 June 1912 â€“ 7 June 1954) was an English mathematician, computer scientist, logician, cryptanalyst, philosopher, and theoretical biologist. Turing was highly influential in the development of theoretical co ...
.


Important results

* Tait showed in 1967 that \beta-reduction is strongly normalizing. As a corollary \beta\eta-equivalence is decidable. Statman showed in 1979 that the normalisation problem is not
elementary recursive Elementary may refer to: Arts, entertainment, and media Music * ''Elementary'' (Cindy Morgan album), 2001 * ''Elementary'' (The End album), 2007 * ''Elementary'', a Melvin "Wah-Wah Watson" Ragin album, 1977 Other uses in arts, entertainment, an ...
, a proof which was later simplified by Mairson. The problem is known to be in the set \mathcal^4 of the
Grzegorczyk hierarchy The Grzegorczyk hierarchy (, ), named after the Polish logician Andrzej Grzegorczyk, is a hierarchy of functions used in computability theory. Every function in the Grzegorczyk hierarchy is a primitive recursive function, and every primitive recurs ...
. A purely semantic normalisation proof (see normalisation by evaluation) was given by Berger and Schwichtenberg in 1991. * The unification problem for \beta\eta-equivalence is undecidable. Huet showed in 1973 that 3rd order unification is undecidable and this was improved upon by Baxter in 1978 then by Goldfarb in 1981 by showing that 2nd order unification is already undecidable. A proof that higher order matching (unification where only one term contains existential variables) is decidable was announced by Colin Stirling in 2006, and a full proof was published in 2009. * We can encode
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 by terms of the type (o\to o)\to(o \to o) (
Church numeral 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 ...
s). Schwichtenberg showed in 1975 that in \lambda^\to exactly the extended
polynomial In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An example ...
s are representable as functions over Church numerals; these are roughly the polynomials closed up under a conditional operator. * A ''full model'' of \lambda^\to is given by interpreting base types as sets and function types by the set-theoretic function space. Friedman showed in 1975 that this interpretation is complete for \beta\eta-equivalence, if the base types are interpreted by infinite sets. Statman showed in 1983 that \beta\eta-equivalence is the maximal equivalence which is ''typically ambiguous'', i.e. closed under type substitutions (''Statman's Typical Ambiguity Theorem''). A corollary of this is that the ''finite model property'' holds, i.e. finite sets are sufficient to distinguish terms which are not identified by \beta\eta-equivalence. * Plotkin introduced logical relations in 1973 to characterize the elements of a model which are definable by lambda terms. In 1993 Jung and Tiuryn showed that a general form of logical relation (Kripke logical relations with varying arity) exactly characterizes lambda definability. Plotkin and Statman conjectured that it is decidable whether a given element of a model generated from finite sets is definable by a lambda term (''Plotkin–Statman conjecture''). The conjecture was shown to be false by Loader in 2001.


Notes


References

* H. Barendregt, tp://ftp.cs.ru.nl/pub/CompMath.Found/HBK.ps Lambda Calculi with Types Handbook of Logic in Computer Science, Volume II, Oxford University Press, 1993. .


External links

* * {{SEP, type-theory-church, Church's Type Theory Lambda calculus Theory of computation Type theory