- Simply typed lambda calculus
The simply typed lambda calculus () is a typed interpretation of the
lambda calculus with only one type combinator: (function type). It is the canonical and simplest example of a typed lambda calculus. The simply typed lambda calculus was originally introduced byAlonzo Church in 1940 as an attempt to avoid paradoxical uses of theuntyped lambda calculus , and it exhibits many desirable and interesting properties.The word "simple types" is also used to refer to extensions of the simply typed lambda calculus such as products,
coproduct s ornatural number s (System T) or even fullrecursion (like PCF). In contrast, systems which introduce polymorphic types (likeSystem F ) or dependent types (like the Logical Framework) are not considered "simply typed". The former are still considered "simple" because theChurch encoding s of such structures can be done using only and suitable type variables, while polymorphism and dependency cannot.Syntax
The syntax of the simply typed lambda calculus is essentially that of the lambda calculus itself. The term syntax used in this article is as follows:
That is, "variable reference", "abstractions", and "application". A variable reference is "bound" if it is inside of an abstraction binding . A term is "closed" if there are no unbound variables.
It is possible to define the syntax as in the
untyped lambda calculus , with unannotated abstractions. Sincetype inference or reconstruction is tractable for the simply typed lambda calculus, the decision doesn't matter from a "typeability" perspective. The type system for the annotated version, however, has an algorithmic interpretation, while the algorithm for type-checking unannotated and partially annotated terms is more complex. For more information, see the article onAlgorithm W .The syntax of types is:
We take and to be "type variables" drawn from a predetermined set, while we reserve and as metavariables, meaning "some type". The "function type" refers to the set of functions that, given an input of type , produce an output of type .
By convention, associates to the right: we read as .
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.
Semantics
There are two distinct presentations of simply typed lambda calculus. In "Curry-style" semantics, the
operational semantics comes first, and the static semantics (typing rules) comes second. In "Church-style" semantics, the static semantics is given first; the operational semantics apply "only" to terms that are accepted by the static semantics.Note that this distinction is not precisely the same as that between unannotated and annotated abstractions. It is possible to give a Curry-style semantics using annotated lambdas: the operational semantics simply ignore types altogether.
Beyond these distinctions, there are then further variations based on calling conventions and
evaluation strategy (call by name ,call by value , etc.) and presentation (big-step, small-step, etc.).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", 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 . It is therefore said that " is "well-typed" (at )". A "typing judgment" is constructed via of the following rules, wherein the premises above the line allow us to derive the conclusion below the line:
In other words,
# If has type in the context, we know that has type .
# 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 .One can construe these judgments not merely as relations between terms and types, but as the construction of terms themselves. This coincides with Church-style semantics, as it is then only possible to construct well-typed terms.Examples of closed terms, i.e. terms typable in the empty context, are:
* (the I-combinator/identity function),
* (the K-combinator), and
* (the S-combinator).These are the typed lambda calculus representations of the basic combinators ofcombinatory logic .In the original presentation, Church used only two base types: for the type of propositions and for the type of individuals. Frequently the calculus with only one base type, usually , is considered.
Terms of the same type are identified via -equivalence, which is generated by the equations , where stands for with all "free" occurrences of replaced by , and , if does not appear free in . The simply typed lambda calculus (with -equivalence) is the internal language of Cartesian Closed Categories (CCCs), this was first observed by Lambek.
Typing without annotations
In the unannotated syntax, lambda abstractions carry no type information. As a consequence, terms can have more than one type. If we consider the type variables to be implicitly universally quantified, then it is possible to find a type more general than the others, called the "
principal type ".For example, the identity function can have many types: , say, or , and so on. Without quantifiers in our type language (as in
System F ), it is impossible to say what type "really" has. Extensions of simply typed lambda calculus can add support for "polymorphism": terms that can have multiple types.System F , for example, adds general abstractions over types: takes a "type" and returns the identity function "at that type". The term has type .If one considers the unannotated lambda calculus extended with constants, such as integers, booleans, and tuples, the problem of typing becomes easier: might be easily determined to have type . The problem above does not go away entirely, though: what type does have? There are an infinite number (, , etc.). The principal type of the term is .
General observations
The simply typed lambda calculus is closely related to propositional
intuitionistic logic using only implication () as a connective (minimal logic) via theCurry-Howard isomorphism : the types inhabited by closed terms are precisely the tautologies of minimal logic.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 abstraction. This is because recursion is not allowed by the typing rules: it is impossible to find types for
fixed-point combinator s and the looping term . Recursion can be added to the language by either having a special operator of type or adding generalrecursive type s, though both eliminate strong normalization.Since it is strongly normalizing, it is decidable whether or not a simply typed lambda calculus program halts: it does! We can therefore conclude that the language is "not"
Turing complete , which has an undecidablehalting problem .Important results
* Tait showed in 1967 that -reduction is strongly normalizing. As a corollary -equivalence is decidable. Statman showed in 1977 that the normalisation problem is not elementary recursive. A purely semantic normalisation proof (see
normalisation by evaluation ) was given by Berger and Schwichtenberg in 1991.
* Theunification problem for -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. Whether higher order matching (unification where only one term contains existential variables) is decidable is still open. [2006: Colin Stirling, Edinburgh, has published a proof-sketch in which he claims that the problem is decidable; however, the complete version of the proof is still unpublished]
* We can encodenatural number s by terms of the type (Church numeral s). Schwichtenberg showed in 1976 that in exactly the extendedpolynomial s are representable as functions over Church numerals; these are roughly the polynomials closed up under a conditional operator.
* A "full model" of is given by interpreting base types as sets and function types by the set-theoreticfunction space . Friedman showed in 1975 that this interpretation is complete for -equivalence, if the base types are interpreted by infinite sets. Statman showed in 1983 that -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 -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 1993.References
* A. Church: A Formulation of the Simple Theory of Types, JSL 5, 1940
* W.W.Tait: Intensional Interpretations of Functionals of Finite Type I, JSL 32(2), 1967
* G.D. Plotkin: Lambda-definability and logical relations, Technical report, 1973
* G.P. Huet: The Undecidability of Unification in Third Order Logic Information and Control 22(3): 257-267 (1973)
* H. Friedman: Equality between functionals. LogicColl. '73, pages 22-37, LNM 453, 1975.
* H. Schwichtenberg: Functions definable in the simply-typed lambda calculus, Arch. Math Logik 17 (1976) 113-114.
* R. Statman: The Typed lambda-Calculus Is not Elementary Recursive FOCS 1977: 90-94
* W. D. Goldfarb: The undecidability of the 2nd order unification problem, TCS (1981), no. 13, 225- 230.
* R. Statman. -definable functionals and conversion. Arch. Math. Logik, 23:21--26, 1983.
* J. Lambek: Cartesian Closed Categories and Typed Lambda-calculi. Combinators and Functional Programming Languages 1985: 136-175
* U. Berger, H. Schwichtenberg: An Inverse of the Evaluation Functional for Typed lambda-calculus LICS 1991: 203-211
* Jung, A.,Tiuryn, J.:A New Characterization of Lambda Definability, TLCA 1993
* R. Loader: [http://homepages.ihug.co.nz/~suckfish/papers/Church.pdf The Undecidability of -definability] , appeared in the Church Festschrift, 2001
* H. Barendregt, [ftp://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. ISBN 0198537611.
* L. Baxter: The undecidability of the third order dyadic unification problem, Information and Control 38(2), 170-178 (1978)See also
* Hindley-Milner type inference algorithm
External links
*
Wikimedia Foundation. 2010.