Simply typed lambda calculus: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
AnomieBOT (talk | contribs)
m Dating maintenance tags: {{Tone}}
Convert most general references to inline citations
Line 1: Line 1:
{{short description|Formal system in mathematical logic}}
{{short description|Formal system in mathematical logic}}
The '''simply typed lambda calculus''' (<math>\lambda^\to</math>), a form
The '''simply typed lambda calculus''' (<math>\lambda^\to</math>), a form
of [[type theory]], is a [[typed lambda calculus|typed interpretation]] of the [[lambda calculus]] with only one [[type constructor]] (<math>\to</math>) that builds [[function type]]s. It is the canonical and simplest example of a typed lambda calculus. The simply typed lambda calculus was originally introduced by [[Alonzo Church]] in 1940 as an attempt to avoid paradoxical uses of the [[untyped lambda calculus]], and it exhibits many desirable and interesting properties.
of [[type theory]], is a [[typed lambda calculus|typed interpretation]] of the [[lambda calculus]] with only one [[type constructor]] (<math>\to</math>) that builds [[function type]]s. It is the canonical and simplest example of a typed lambda calculus. The simply typed lambda calculus was originally introduced by [[Alonzo Church]] in 1940 as an attempt to avoid paradoxical uses of the [[untyped lambda calculus]].<ref name="Church 1940" />


The term ''simple type'' is also used to refer to extensions of the simply typed lambda calculus such as [[cartesian product|products]], [[coproduct]]s or [[natural number]]s ([[Dialectica interpretation|System T]]) or even full [[recursion]] (like [[Programming language for Computable Functions|PCF]]). In contrast, systems which introduce [[parametric polymorphism|polymorphic type]]s (like [[System F]]) or [[dependent type]]s (like the [[LF (logical framework)|Logical Framework]]) are not considered ''simply typed''. The simple types, except for full recursion, are still considered ''simple'' because the [[Church encoding]]s of such structures can be done using only <math>\to</math> and suitable type variables, while polymorphism and dependency cannot.
The term ''simple type'' is also used to refer to extensions of the simply typed lambda calculus such as [[cartesian product|products]], [[coproduct]]s or [[natural number]]s ([[Dialectica interpretation|System T]]) or even full [[recursion]] (like [[Programming language for Computable Functions|PCF]]). In contrast, systems which introduce [[parametric polymorphism|polymorphic type]]s (like [[System F]]) or [[dependent type]]s (like the [[LF (logical framework)|Logical Framework]]) are not considered ''simply typed''. The simple types, except for full recursion, are still considered ''simple'' because the [[Church encoding]]s of such structures can be done using only <math>\to</math> and suitable type variables, while polymorphism and dependency cannot.
Line 70: Line 70:
=== Intrinsic vs. extrinsic interpretations ===
=== 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.{{sfn|Church|1940}}{{r|Curry|r={{cite journal|author-link=Haskell Curry| last = Curry| first = Haskell B| date = 1934-09-20| title = Functionality in Combinatory Logic| journal = Proceedings of the National Academy of Sciences of the United States of America| volume = 20| issue = 11| pages = 584–90| pmid = 16577644| pmc = 1076489| doi = 10.1073/pnas.20.11.584| issn = 0027-8424| bibcode = 1934PNAS...20..584C| doi-access = free}} (presents an extrinsically typed combinatory logic, later adapted by others to the lambda calculus)<ref>{{cite journal |last1=Pfenning |first1=Frank |title=Church and Curry: Combining Intrinsic and Extrinsic Typing |page=1 |url=https://www.cs.cmu.edu/~fp/papers/andrews08.pdf |access-date=26 February 2022}}</ref>}}<ref>{{cite book| first = John | last = Reynolds | author-link=John_C._Reynolds| publisher = Cambridge University Press| location = Cambridge, England| title=Theories of Programming Languages| url = https://archive.org/details/theoriesofprogra0000reyn | url-access = registration | year=1998|pages=327,334| isbn = 9780521594141 }}</ref>
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.<ref name="Church 1940" />{{r|Curry|r={{cite journal|author-link=Haskell Curry| last = Curry| first = Haskell B| date = 1934-09-20| title = Functionality in Combinatory Logic| journal = Proceedings of the National Academy of Sciences of the United States of America| volume = 20| issue = 11| pages = 584–90| pmid = 16577644| pmc = 1076489| doi = 10.1073/pnas.20.11.584| issn = 0027-8424| bibcode = 1934PNAS...20..584C| doi-access = free}} (presents an extrinsically typed combinatory logic, later adapted by others to the lambda calculus)<ref>{{cite journal |last1=Pfenning |first1=Frank |title=Church and Curry: Combining Intrinsic and Extrinsic Typing |page=1 |url=https://www.cs.cmu.edu/~fp/papers/andrews08.pdf |access-date=26 February 2022}}</ref>}}<ref>{{cite book| first = John | last = Reynolds | author-link=John_C._Reynolds| publisher = Cambridge University Press| location = Cambridge, England| title=Theories of Programming Languages| url = https://archive.org/details/theoriesofprogra0000reyn | url-access = registration | year=1998|pages=327,334| isbn = 9780521594141 }}</ref>
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 <math>\lambda x\mathbin{:}\mathtt{int}.~x</math> on integers and the identity term <math>\lambda x\mathbin{:}\mathtt{bool}.~x</math> on booleans may mean different things. (The classic intended interpretations
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 <math>\lambda x\mathbin{:}\mathtt{int}.~x</math> on integers and the identity term <math>\lambda x\mathbin{:}\mathtt{bool}.~x</math> on booleans may mean different things. (The classic intended interpretations
are the identity function on integers and the identity function on boolean values.)
are the identity function on integers and the identity function on boolean values.)
Line 90: Line 90:


=== Categorical semantics ===
=== Categorical semantics ===
The simply typed lambda calculus (with <math>\beta\eta</math>-equivalence) is the [[internal language]] of [[Cartesian closed categories]] (CCCs), as was first observed by [[Joachim Lambek|Lambek]]. Given any specific CCC, the basic types of the corresponding lambda calculus are just the [[object (category theory)|objects]], and the terms are the [[morphism]]s. Conversely, every simply typed lambda calculus gives a CCC whose objects are the types, and morphisms are equivalence classes of terms.
The simply typed lambda calculus (with <math>\beta\eta</math>-equivalence) is the [[internal language]] of [[Cartesian closed categories]] (CCCs), as was first observed by [[Joachim Lambek]].<ref name="Lambek 1985" /> Given any specific CCC, the basic types of the corresponding lambda calculus are just the [[object (category theory)|objects]], and the terms are the [[morphism]]s. 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]] for the [[Cartesian product]] is typically added to the above. To preserve the [[product (category theory)|categoricity of the Cartesian product]], one adds [[type rule]]s for ''pairing'', ''projection'', and a ''unit term''. Given two terms <math>s\mathbin{:}\sigma</math> and <math>t\mathbin{:}\tau</math>, the term <math>(s,t)</math> has type <math>\sigma\times\tau</math>. Likewise, if one has a term <math>u\mathbin{:}\tau_1\times\tau_2</math>, then there are terms <math>\pi_1(u)\mathbin{:}\tau_1</math> and <math>\pi_2(u)\mathbin{:}\tau_2</math> where the <math>\pi_i</math> correspond to the projections of the Cartesian product. The ''unit term'', of type 1, is written as <math>()</math> and vocalized as 'nil', is the [[final object]]. The equational theory is extended likewise, so that one has
To make the correspondence clear, a [[type constructor]] for the [[Cartesian product]] is typically added to the above. To preserve the [[product (category theory)|categoricity of the Cartesian product]], one adds [[type rule]]s for ''pairing'', ''projection'', and a ''unit term''. Given two terms <math>s\mathbin{:}\sigma</math> and <math>t\mathbin{:}\tau</math>, the term <math>(s,t)</math> has type <math>\sigma\times\tau</math>. Likewise, if one has a term <math>u\mathbin{:}\tau_1\times\tau_2</math>, then there are terms <math>\pi_1(u)\mathbin{:}\tau_1</math> and <math>\pi_2(u)\mathbin{:}\tau_2</math> where the <math>\pi_i</math> correspond to the projections of the Cartesian product. The ''unit term'', of type 1, is written as <math>()</math> and vocalized as 'nil', is the [[final object]]. The equational theory is extended likewise, so that one has
Line 145: Line 145:
== Important results ==
== Important results ==


* Tait showed in 1967 that <math>\beta</math>-reduction is [[Normalization property (lambda-calculus)|strongly normalizing]]. As a corollary <math>\beta\eta</math>-equivalence is [[decidability (logic)|decidable]]. Statman showed in 1977 that the normalisation problem is not [[elementary recursive]], a proof which was later simplified by Mairson (1992). The problem is known to be in the set <math>\mathcal{E}^4</math> of the [[Grzegorczyk hierarchy]].<ref>{{cite journal |last1=Statman |first1=Richard |title=The typed λ-calculus is not elementary recursive |journal=Theoretical Computer Science |date=July 1979 |volume=9 |issue=1 |pages=73–81 |doi=10.1016/0304-3975(79)90007-0 |language=en |issn=0304-3975|doi-access=free }}</ref> A purely semantic normalisation proof (see [[normalisation by evaluation]]) was given by Berger and Schwichtenberg in 1991.
* Tait showed in 1967 that <math>\beta</math>-reduction is [[Normalization property (lambda-calculus)|strongly normalizing]].<ref name="Tait 1967" /> As a corollary <math>\beta\eta</math>-equivalence is [[decidability (logic)|decidable]]. Statman showed in 1979 that the normalisation problem is not [[elementary recursive]],<ref name="Statman 1979" /> a proof which was later simplified by Mairson.<ref name="Mairson 1992" /> The problem is known to be in the set <math>\mathcal{E}^4</math> of the [[Grzegorczyk hierarchy]].<ref>{{cite journal |last1=Statman |first1=Richard |title=The typed λ-calculus is not elementary recursive |journal=Theoretical Computer Science |date=July 1979 |volume=9 |issue=1 |pages=73–81 |doi=10.1016/0304-3975(79)90007-0 |language=en |issn=0304-3975|doi-access=free }}</ref> A purely semantic normalisation proof (see [[normalisation by evaluation]]) was given by Berger and Schwichtenberg in 1991.<ref name="Berger 1991" />
* The [[unification (computing)|unification]] problem for <math>\beta\eta</math>-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.<ref>{{cite journal|last1=Stirling|first1=Colin|title=Decidability of higher-order matching|journal=Logical Methods in Computer Science|date=22 July 2009|volume=5|issue=3|pages=1–52|doi=10.2168/LMCS-5(3:2)2009|arxiv=0907.3804|s2cid=1478837}}</ref>
* The [[unification (computing)|unification]] problem for <math>\beta\eta</math>-equivalence is undecidable. Huet showed in 1973 that 3rd order unification is undecidable<ref name="Huet 1973" /> and this was improved upon by Baxter in 1978<ref name="Baxter 1978" /> then by Goldfarb in 1981<ref name="Goldfarb 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.<ref>{{cite journal|last1=Stirling|first1=Colin|title=Decidability of higher-order matching|journal=Logical Methods in Computer Science|date=22 July 2009|volume=5|issue=3|pages=1–52|doi=10.2168/LMCS-5(3:2)2009|arxiv=0907.3804|s2cid=1478837}}</ref>
* We can encode [[natural number]]s by terms of the type <math>(o\to o)\to(o \to o)</math> ([[Church numeral]]s). Schwichtenberg showed in 1976 that in <math>\lambda^\to</math> exactly the extended [[polynomial]]s are representable as functions over Church numerals; these are roughly the polynomials closed up under a conditional operator.
* We can encode [[natural number]]s by terms of the type <math>(o\to o)\to(o \to o)</math> ([[Church numeral]]s). Schwichtenberg showed in 1975 that in <math>\lambda^\to</math> exactly the extended [[polynomial]]s are representable as functions over Church numerals;<ref name="Schwichtenberg 1975" /> these are roughly the polynomials closed up under a conditional operator.
* A ''full model'' of <math>\lambda^\to</math> is given by interpreting base types as [[Set (mathematics)|sets]] and function types by the set-theoretic [[function space]]. Friedman showed in 1975 that this interpretation is [[Completeness (logic)|complete]] for <math>\beta\eta</math>-equivalence, if the base types are interpreted by infinite sets. Statman showed in 1983 that <math>\beta\eta</math>-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 <math>\beta\eta</math>-equivalence.
* A ''full model'' of <math>\lambda^\to</math> is given by interpreting base types as [[Set (mathematics)|sets]] and function types by the set-theoretic [[function space]]. Friedman showed in 1975 that this interpretation is [[Completeness (logic)|complete]] for <math>\beta\eta</math>-equivalence, if the base types are interpreted by infinite sets.<ref name="Friedman 1975" /> Statman showed in 1983 that <math>\beta\eta</math>-equivalence is the maximal equivalence which is ''typically ambiguous'', i.e. closed under type substitutions (''Statman's Typical Ambiguity Theorem'').<ref name="Statman 1983" /> 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 <math>\beta\eta</math>-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.
* Plotkin introduced logical relations in 1973 to characterize the elements of a model which are definable by lambda terms.<ref name="Plotkin 1973" /> In 1993 Jung and Tiuryn showed that a general form of logical relation (Kripke logical relations with varying arity) exactly characterizes lambda definability.<ref name="Jung 1993" /> 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.<ref name="Loader 2001" />


== Notes ==
== Notes ==


{{reflist}}
{{reflist|refs=
<ref name="Church 1940">{{cite journal|author-link=Alonzo Church |last1=Church |first1=Alonzo |title=A formulation of the simple theory of types |journal=Journal of Symbolic Logic |date=June 1940 |volume=5 |issue=2 |pages=56–68 |doi=10.2307/2266170|jstor=2266170 |s2cid=15889861 |url=https://web.archive.org/web/20190112232531/https://pdfs.semanticscholar.org/28bf/123690205ae5bbd9f8c84b1330025e8476e4.pdf}}</ref>
<ref name="Lambek 1985">{{cite book |last1=Lambek |first1=J. |title=Cartesian closed categories and typed λ-calculi |date=1986 |publisher=Springer |isbn=978-3-540-47253-7 |pages=136–175 |url=https://link.springer.com/chapter/10.1007/3-540-17184-3_44 |language=en}}</ref>
<ref name="Tait 1967">{{cite journal |author-link=William W. Tait |last1=Tait |first1=W. W. |title=Intensional interpretations of functionals of finite type I |journal=The Journal of Symbolic Logic |date=August 1967 |volume=32 |issue=2 |pages=198–212 |doi=10.2307/2271658 |url=https://doi.org/10.2307/2271658 |language=en |issn=0022-4812}}</ref>
<ref name="Statman 1979">{{cite journal |last1=Statman |first1=Richard |title=The typed λ-calculus is not elementary recursive |journal=Theoretical Computer Science |date=1 July 1979 |volume=9 |issue=1 |pages=73–81 |doi=10.1016/0304-3975(79)90007-0 |url=https://www.sciencedirect.com/science/article/pii/0304397579900070 |language=en |issn=0304-3975}}</ref>
<ref name="Mairson 1992">{{cite journal |last1=Mairson |first1=Harry G. |title=A simple proof of a theorem of Statman |journal=Theoretical Computer Science |date=14 September 1992 |volume=103 |issue=2 |pages=387–394 |doi=10.1016/0304-3975(92)90020-G |url=https://www.sciencedirect.com/science/article/pii/030439759290020G |language=en |issn=0304-3975}}</ref>
<ref name="Berger 1991">{{cite journal |last1=Berger |first1=U. |last2=Schwichtenberg |first2=H. |title=An inverse of the evaluation functional for typed lambda-calculus |journal=[1991] Proceedings Sixth Annual IEEE Symposium on Logic in Computer Science |date=July 1991 |pages=203–211 |doi=10.1109/LICS.1991.151645 |url=https://doi.org/10.1109/LICS.1991.151645}}</ref>
<ref name="Huet 1973">{{cite journal |last1=Huet |first1=Gerard P. |title=The undecidability of unification in third order logic |journal=Information and Control |date=1 April 1973 |volume=22 |issue=3 |pages=257–267 |doi=10.1016/S0019-9958(73)90301-X |url=https://doi.org/10.1016/S0019-9958(73)90301-X |language=en |issn=0019-9958}}</ref>
<ref name="Baxter 1978">{{cite journal |last1=Baxter |first1=Lewis D. |title=The undecidability of the third order dyadic unification problem |journal=Information and Control |date=1 August 1978 |volume=38 |issue=2 |pages=170–178 |doi=10.1016/S0019-9958(78)90172-9 |url=https://doi.org/10.1016/S0019-9958(78)90172-9 |language=en |issn=0019-9958}}</ref>
<ref name="Goldfarb 1981">{{cite journal |last1=Goldfarb |first1=Warren D. |title=The undecidability of the second-order unification problem |journal=Theoretical Computer Science |date=1 January 1981 |volume=13 |issue=2 |pages=225–230 |doi=10.1016/0304-3975(81)90040-2 |url=https://doi.org/10.1016/0304-3975(81)90040-2 |language=en |issn=0304-3975}}</ref>
<ref name="Schwichtenberg 1975">{{cite journal |last1=Schwichtenberg |first1=Helmut |title=Definierbare Funktionen imλ-Kalkül mit Typen |journal=Archiv für mathematische Logik und Grundlagenforschung |date=1 September 1975 |volume=17 |issue=3 |pages=113–114 |doi=10.1007/BF02276799 |url=https://doi.org/10.1007/BF02276799 |language=de |issn=1432-0665}}</ref>
<ref name="Friedman 1975">{{cite journal |last1=Friedman |first1=Harvey |title=Equality between functionals |journal=Logic Colloquium |date=1975 |pages=22–37 |doi=10.1007/BFb0064870 |url=https://doi.org/10.1007/BFb0064870 |publisher=Springer |language=en}}</ref>
<ref name="Statman 1983">{{cite journal |last1=Statman |first1=R. |title=<math>\lambda</math>-definable functionals and <math>\beta\eta</math> conversion |journal=Archiv für mathematische Logik und Grundlagenforschung |date=1 December 1983 |volume=23 |issue=1 |pages=21–26 |doi=10.1007/BF02023009 |url=https://doi.org/10.1007/BF02023009 |language=en |issn=1432-0665}}</ref>
<ref name="Plotkin 1973">{{cite techreport |first=G.D. |last=Plotkin |title=Lambda-definability and logical relations |date=1973 |institution=Edinburgh University |url=https://www.cl.cam.ac.uk/~nk480/plotkin-logical-relations.pdf |access-date=30 September 2022}}</ref>
<ref name="Jung 1993">{{cite journal |last1=Jung |first1=Achim |last2=Tiuryn |first2=Jerzy |title=A new characterization of lambda definability |journal=Typed Lambda Calculi and Applications |date=1993 |pages=245–257 |doi=10.1007/BFb0037110 |url=https://doi.org/10.1007/BFb0037110 |publisher=Springer |language=en}}</ref>
<ref name="Loader 2001">{{cite journal |last1=Loader |first1=Ralph |title=The Undecidability of λ-Definability |journal=Logic, Meaning and Computation: Essays in Memory of Alonzo Church |date=2001 |pages=331–342 |doi=10.1007/978-94-010-0526-5_15 |url=https://doi.org/10.1007/978-94-010-0526-5_15 |publisher=Springer Netherlands |language=en}}</ref>
}}


== References ==
== References ==


* {{cite journal|author-link=Alonzo Church |last1=Church |first1=Alonzo |title=A formulation of the simple theory of types |journal=Journal of Symbolic Logic |date=June 1940 |volume=5 |issue=2 |pages=56–68 |doi=10.2307/2266170|jstor=2266170 |s2cid=15889861 |url=https://web.archive.org/web/20190112232531/https://pdfs.semanticscholar.org/28bf/123690205ae5bbd9f8c84b1330025e8476e4.pdf}}
* [[William W. Tait|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: [https://core.ac.uk/download/pdf/82722816.pdf The Undecidability of Unification in Third Order Logic] Information and Control 22(3): 257-267 (1973)
* H. Friedman: [https://link.springer.com/content/pdf/10.1007/BFb0064870.pdf 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: [https://www.sciencedirect.com/science/article/pii/0304397579900070/pdf?md5=c135c4c87182b368820db48fccffbb8d&pid=1-s2.0-0304397579900070-main.pdf&_valck=1 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. <math>\lambda</math>-definable functionals and <math>\beta\eta</math> conversion. Arch. Math. Logik, 23:21–26, 1983.
* [[Joachim Lambek|J. Lambek]]: [https://link.springer.com/content/pdf/10.1007/3-540-17184-3_44.pdf Cartesian Closed Categories and Typed Lambda-calculi]. Combinators and Functional Programming Languages 1985: 136-175
* U. Berger, H. Schwichtenberg: [https://epub.ub.uni-muenchen.de/4261/1/4261.pdf An Inverse of the Evaluation Functional for Typed lambda-calculus] LICS 1991: 203-211
* H. Mairson: [https://www.sciencedirect.com/science/article/pii/030439759290020G/pdf?md5=4a72ea7e53bcf4f25de0c1cf2af0d3d1&isDTMRedir=Y&pid=1-s2.0-030439759290020G-main.pdf A simple proof of a theorem of Statman], TCS 103(2):387-394, 1992.
* Jung, A.,Tiuryn, J.:[http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.37.363&rep=rep1&type=pdf 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|0-19-853761-1}}.
* 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|0-19-853761-1}}.
* L. Baxter: [https://core.ac.uk/download/pdf/82612292.pdf The undecidability of the third order dyadic unification problem], Information and Control 38(2), 170-178 (1978)


== External links ==
== External links ==

Revision as of 21:42, 30 September 2022

The simply typed lambda calculus (), a form of type theory, is a typed interpretation of the lambda calculus 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 in 1940 as an attempt to avoid paradoxical uses of the untyped lambda calculus.[1]

The term simple type is also used to refer to extensions of the simply typed lambda calculus such as products, coproducts or natural numbers (System T) or even full recursion (like PCF). In contrast, systems which 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 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 nat, 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:

(1) (2)
(3) (4)

In words,

  1. If has type in the context, we know that has type .
  2. Term constants have the appropriate base types.
  3. If, in a certain context with having type , has type , then, in the same context without , has type .
  4. 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.[1][3][4] 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), 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). 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 of βη-equivalence as untyped lambda calculus, but subject to type restrictions. The equation for beta reduction

holds in context whenever and , while the equation for eta reduction

holds whenever and does not appear free in .

Operational semantics

Likewise, the operational semantics of simply typed lambda calculus can be fixed as for the untyped lambda calculus, using call by name, call by value, or other evaluation strategies. As for any typed language, type safety 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 -equivalence) is the internal language of Cartesian closed categories (CCCs), as was first observed by Joachim Lambek.[5] 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 for the Cartesian product is typically added to the above. To preserve the categoricity of the Cartesian product, one adds type rules for pairing, projection, and a unit term. Given two terms and , the term has type . Likewise, if one has a term , then there are terms and where the 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. The equational theory is extended likewise, so that one has

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 are equivalence classes of pairs where x is a variable (of type ) and t is a term (of type ), having no free variables in it, except for (optionally) x. Closure is obtained from currying and application, as usual.

More precisely, there exist functors 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. 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. This is fine for laying the foundations of set theory, but the more general topos 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, i.e., minimal logic, via the Curry–Howard isomorphism: terms correspond precisely to proofs in natural deduction, 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, since often an unannotated term (such as ) may have more than one type (, , etc., which are all instances of the principal type ).

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 is divided into two judgments, representing both checking and synthesis, written and respectively. Operationally, the three components , , and are all inputs to the checking judgment , whereas the synthesis judgment only takes and as inputs, producing the type as output. These judgments are derived via the following rules:

[1] [2]
[3] [4]
[5] [6]

Observe that rules [1]–[4] 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:

  1. If is in the context, we can synthesize type for .
  2. The types of term constants are fixed and can be synthesized.
  3. To check that has type in some context, we extend the context with and check that has type .
  4. If synthesizes type (in some context), and checks against type (in the same context), then synthesizes type .

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 [3], because the type of the bound variable can be deduced from the type at which we check the function. Finally, we explain rules [5] and [6] as follows:

  1. To check that has type , it suffices to synthesize type .
  2. If checks against type , then the explicitly annotated term synthesizes .

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 abstraction. This is because recursion is not allowed by the typing rules: it is impossible to find types for fixed-point combinators and the looping term . Recursion can be added to the language by either having a special operator of type or adding general recursive types, 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.

Important results

  • Tait showed in 1967 that -reduction is strongly normalizing.[6] As a corollary -equivalence is decidable. Statman showed in 1979 that the normalisation problem is not elementary recursive,[7] a proof which was later simplified by Mairson.[8] The problem is known to be in the set of the Grzegorczyk hierarchy.[9] A purely semantic normalisation proof (see normalisation by evaluation) was given by Berger and Schwichtenberg in 1991.[10]
  • The unification problem for -equivalence is undecidable. Huet showed in 1973 that 3rd order unification is undecidable[11] and this was improved upon by Baxter in 1978[12] then by Goldfarb in 1981[13] 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.[14]
  • We can encode natural numbers by terms of the type (Church numerals). Schwichtenberg showed in 1975 that in exactly the extended polynomials are representable as functions over Church numerals;[15] 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-theoretic function space. Friedman showed in 1975 that this interpretation is complete for -equivalence, if the base types are interpreted by infinite sets.[16] 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).[17] 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.[18] In 1993 Jung and Tiuryn showed that a general form of logical relation (Kripke logical relations with varying arity) exactly characterizes lambda definability.[19] 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.[20]

Notes

  1. ^ a b Church, Alonzo (June 1940). "A formulation of the simple theory of types" (PDF). Journal of Symbolic Logic. 5 (2): 56–68. doi:10.2307/2266170. JSTOR 2266170. S2CID 15889861.
  2. ^ Pfenning, Frank. "Church and Curry: Combining Intrinsic and Extrinsic Typing" (PDF): 1. Retrieved 26 February 2022. {{cite journal}}: Cite journal requires |journal= (help)
  3. ^ Curry, Haskell B (1934-09-20). "Functionality in Combinatory Logic". Proceedings of the National Academy of Sciences of the United States of America. 20 (11): 584–90. Bibcode:1934PNAS...20..584C. doi:10.1073/pnas.20.11.584. ISSN 0027-8424. PMC 1076489. PMID 16577644. (presents an extrinsically typed combinatory logic, later adapted by others to the lambda calculus)[2]
  4. ^ Reynolds, John (1998). Theories of Programming Languages. Cambridge, England: Cambridge University Press. pp. 327, 334. ISBN 9780521594141.
  5. ^ Lambek, J. (1986). Cartesian closed categories and typed λ-calculi. Springer. pp. 136–175. ISBN 978-3-540-47253-7.
  6. ^ Tait, W. W. (August 1967). "Intensional interpretations of functionals of finite type I". The Journal of Symbolic Logic. 32 (2): 198–212. doi:10.2307/2271658. ISSN 0022-4812.
  7. ^ Statman, Richard (1 July 1979). "The typed λ-calculus is not elementary recursive". Theoretical Computer Science. 9 (1): 73–81. doi:10.1016/0304-3975(79)90007-0. ISSN 0304-3975.
  8. ^ Mairson, Harry G. (14 September 1992). "A simple proof of a theorem of Statman". Theoretical Computer Science. 103 (2): 387–394. doi:10.1016/0304-3975(92)90020-G. ISSN 0304-3975.
  9. ^ Statman, Richard (July 1979). "The typed λ-calculus is not elementary recursive". Theoretical Computer Science. 9 (1): 73–81. doi:10.1016/0304-3975(79)90007-0. ISSN 0304-3975.
  10. ^ Berger, U.; Schwichtenberg, H. (July 1991). "An inverse of the evaluation functional for typed lambda-calculus". [1991] Proceedings Sixth Annual IEEE Symposium on Logic in Computer Science: 203–211. doi:10.1109/LICS.1991.151645.
  11. ^ Huet, Gerard P. (1 April 1973). "The undecidability of unification in third order logic". Information and Control. 22 (3): 257–267. doi:10.1016/S0019-9958(73)90301-X. ISSN 0019-9958.
  12. ^ Baxter, Lewis D. (1 August 1978). "The undecidability of the third order dyadic unification problem". Information and Control. 38 (2): 170–178. doi:10.1016/S0019-9958(78)90172-9. ISSN 0019-9958.
  13. ^ Goldfarb, Warren D. (1 January 1981). "The undecidability of the second-order unification problem". Theoretical Computer Science. 13 (2): 225–230. doi:10.1016/0304-3975(81)90040-2. ISSN 0304-3975.
  14. ^ Stirling, Colin (22 July 2009). "Decidability of higher-order matching". Logical Methods in Computer Science. 5 (3): 1–52. arXiv:0907.3804. doi:10.2168/LMCS-5(3:2)2009. S2CID 1478837.
  15. ^ Schwichtenberg, Helmut (1 September 1975). "Definierbare Funktionen imλ-Kalkül mit Typen". Archiv für mathematische Logik und Grundlagenforschung (in German). 17 (3): 113–114. doi:10.1007/BF02276799. ISSN 1432-0665.
  16. ^ Friedman, Harvey (1975). "Equality between functionals". Logic Colloquium. Springer: 22–37. doi:10.1007/BFb0064870.
  17. ^ Statman, R. (1 December 1983). "-definable functionals and conversion". Archiv für mathematische Logik und Grundlagenforschung. 23 (1): 21–26. doi:10.1007/BF02023009. ISSN 1432-0665.
  18. ^ Plotkin, G.D. (1973). Lambda-definability and logical relations (PDF) (Technical report). Edinburgh University. Retrieved 30 September 2022.
  19. ^ Jung, Achim; Tiuryn, Jerzy (1993). "A new characterization of lambda definability". Typed Lambda Calculi and Applications. Springer: 245–257. doi:10.1007/BFb0037110.
  20. ^ Loader, Ralph (2001). "The Undecidability of λ-Definability". Logic, Meaning and Computation: Essays in Memory of Alonzo Church. Springer Netherlands: 331–342. doi:10.1007/978-94-010-0526-5_15.

References

External links