Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

System F

From Wikipedia, the free encyclopedia
(Redirected fromSystem F-sub)
Typed lambda calculus
For the electronic trance music artist, seeFerry Corsten.

System F (alsopolymorphic lambda calculus orsecond-order lambda calculus) is atyped lambda calculus that introduces, tosimply typed lambda calculus, a mechanism ofuniversal quantification over types. System F formalizesparametric polymorphism inprogramming languages, thus forming a theoretical basis for languages such asHaskell andML. It was discovered independently bylogicianJean-Yves Girard (1972) andcomputer scientistJohn C. Reynolds.

Whereassimply typed lambda calculus has variables ranging over terms, and binders for them, System F additionally has variables ranging overtypes, and binders for them. As an example, the fact that the identity function can have any type of the formAA would be formalized in System F as the statement

Λα.λxα.x:α.αα{\displaystyle \vdash \Lambda \alpha .\lambda x^{\alpha }.x:\forall \alpha .\alpha \to \alpha }

whereα{\displaystyle \alpha } is atype variable. The upper-caseΛ{\displaystyle \Lambda } is traditionally used to denote type-level functions, as opposed to the lower-caseλ{\displaystyle \lambda } which is used for value-level functions. (The superscriptedα{\displaystyle \alpha } means that the bound variablex is of typeα{\displaystyle \alpha }; the expression after the colon is the type of the lambda expression preceding it.)

As aterm rewriting system, System F isstrongly normalizing. However,type inference in System F (without explicit type annotations) isundecidable. Under theCurry–Howard isomorphism, System F corresponds tosecond-order propositional intuitionistic logic. System F can be seen as part of thelambda cube, together with even more expressive typed lambda calculi, including those withdependent types.

According to Girard, the "F" inSystem F was picked by chance.[1]

Typing rules

[edit]

The typing rules of System F are those of simply typed lambda calculus with the addition of the following:

ΓM:α.σΓMτ:σ[τ/α]{\displaystyle {\frac {\Gamma \vdash M:\forall \alpha .\sigma }{\Gamma \vdash M\tau :\sigma [\tau /\alpha ]}}} (1)Γ,α typeM:σΓΛα.M:α.σ{\displaystyle {\frac {\Gamma ,\alpha ~{\text{type}}\vdash M:\sigma }{\Gamma \vdash \Lambda \alpha .M:\forall \alpha .\sigma }}} (2)

whereσ,τ{\displaystyle \sigma ,\tau } are types,α{\displaystyle \alpha } is a type variable, andα type{\displaystyle \alpha ~{\text{type}}} in the context indicates thatα{\displaystyle \alpha } is bound. The first rule is that of application, and the second is that of abstraction.[2][3]

Logic and predicates

[edit]

TheBoolean{\displaystyle {\mathsf {Boolean}}} type is defined as:α.ααα{\displaystyle \forall \alpha .\alpha \to \alpha \to \alpha }, whereα{\displaystyle \alpha } is atype variable. This means:Boolean{\displaystyle {\mathsf {Boolean}}} is the type of all functions which take as input a type α and two expressions of type α, and produce as output an expression of type α (note that we consider{\displaystyle \to } to beright-associative.)

The following two definitions for the Boolean valuesT{\displaystyle \mathbf {T} } andF{\displaystyle \mathbf {F} } are used, extending the definition ofChurch Booleans:

T=Λα.λxαλyα.x{\displaystyle \mathbf {T} =\Lambda \alpha {.}\lambda x^{\alpha }\lambda y^{\alpha }{.}x}
F=Λα.λxαλyα.y{\displaystyle \mathbf {F} =\Lambda \alpha {.}\lambda x^{\alpha }\lambda y^{\alpha }{.}y}

(Note that the above two functions requirethree — not two — arguments. The latter two should be lambda expressions, but the first one should be a type. This fact is reflected in the fact that the type of these expressions isα.ααα{\displaystyle \forall \alpha .\alpha \to \alpha \to \alpha }; the universal quantifier binding the α corresponds to the Λ binding the alpha in the lambda expression itself. Also, note thatBoolean{\displaystyle {\mathsf {Boolean}}} is a convenient shorthand forα.ααα{\displaystyle \forall \alpha .\alpha \to \alpha \to \alpha }, but it is not a symbol of System F itself, but rather a "meta-symbol". Likewise,T{\displaystyle \mathbf {T} } andF{\displaystyle \mathbf {F} } are also "meta-symbols", convenient shorthands, of System F "assemblies" (in theBourbaki sense); otherwise, if such functions could be named (within System F), then there would be no need for the lambda-expressive apparatus capable of defining functions anonymously and for thefixed-point combinator, which works around that restriction.)

Then, with these twoλ{\displaystyle \lambda }-terms, we can define some logic operators (which are of typeBooleanBooleanBoolean{\displaystyle {\mathsf {Boolean}}\rightarrow {\mathsf {Boolean}}\rightarrow {\mathsf {Boolean}}}):

AND=λxBooleanλyBoolean.xBooleanyFOR=λxBooleanλyBoolean.xBooleanTyNOT=λxBoolean.xBooleanFT{\displaystyle {\begin{aligned}\mathrm {AND} &=\lambda x^{\mathsf {Boolean}}\lambda y^{\mathsf {Boolean}}{.}x\,{\mathsf {Boolean}}\,y\,\mathbf {F} \\\mathrm {OR} &=\lambda x^{\mathsf {Boolean}}\lambda y^{\mathsf {Boolean}}{.}x\,{\mathsf {Boolean}}\,\mathbf {T} \,y\\\mathrm {NOT} &=\lambda x^{\mathsf {Boolean}}{.}x\,{\mathsf {Boolean}}\,\mathbf {F} \,\mathbf {T} \end{aligned}}}

Note that in the definitions above,Boolean{\displaystyle {\mathsf {Boolean}}} is a type argument tox{\displaystyle x}, specifying that the other two parameters that are given tox{\displaystyle x} are of typeBoolean{\displaystyle {\mathsf {Boolean}}}. As in Church encodings, there is no need for anIFTHENELSE function as one can just use rawBoolean{\displaystyle {\mathsf {Boolean}}}-typed terms as decision functions. However, if one is requested:

IFTHENELSE=Λα.λxBooleanλyαλzα.xαyz{\displaystyle \mathrm {IFTHENELSE} =\Lambda \alpha .\lambda x^{\mathsf {Boolean}}\lambda y^{\alpha }\lambda z^{\alpha }.x\alpha yz}

will do.Apredicate is a function which returns aBoolean{\displaystyle {\mathsf {Boolean}}}-typed value. The most fundamental predicate isISZERO which returnsT{\displaystyle \mathbf {T} } if and only if its argument is theChurch numeral0:

ISZERO=λnα.(αα)αα.nBoolean(λxBoolean.F)T{\displaystyle \mathrm {ISZERO} =\lambda n^{\forall \alpha .(\alpha \rightarrow \alpha )\rightarrow \alpha \rightarrow \alpha }{.}n\,{\mathsf {Boolean}}\,(\lambda x^{\mathsf {Boolean}}{.}\mathbf {F} )\,\mathbf {T} }

Furthermore, theexistential quantifier (and therefore existential types) can be implemented in system F by the following:[4][5]

X.A=Y.(X.AY)Y{\displaystyle \exists X.A=\forall Y.(\forall X.A\rightarrow Y)\rightarrow Y}

System F structures

[edit]

System F allows recursive constructions to be embedded in a natural manner, related to that inMartin-Löf's type theory. Abstract structures (S) are created usingconstructors. These are functions typed as:

K1K2S{\displaystyle K_{1}\rightarrow K_{2}\rightarrow \dots \rightarrow S}.

Recursivity is manifested whenS itself appears within one of the typesKi{\displaystyle K_{i}}. If you havem of these constructors, you can define the type ofS as:

α.(K11[α/S]α)(K1m[α/S]α)α{\displaystyle \forall \alpha .(K_{1}^{1}[\alpha /S]\rightarrow \dots \rightarrow \alpha )\dots \rightarrow (K_{1}^{m}[\alpha /S]\rightarrow \dots \rightarrow \alpha )\rightarrow \alpha }

For instance, the natural numbers can be defined as an inductive datatypeN with constructors

zero:Nsucc:NN{\displaystyle {\begin{aligned}{\mathit {zero}}&:\mathrm {N} \\{\mathit {succ}}&:\mathrm {N} \rightarrow \mathrm {N} \end{aligned}}}

The System F type corresponding to this structure isα.α(αα)α{\displaystyle \forall \alpha .\alpha \to (\alpha \to \alpha )\to \alpha }. The terms of this type comprise a typed version of theChurch numerals, the first few of which are:

0:=Λα.λxα.λfαα.x1:=Λα.λxα.λfαα.fx2:=Λα.λxα.λfαα.f(fx)3:=Λα.λxα.λfαα.f(f(fx)){\displaystyle {\begin{aligned}0&:=\Lambda \alpha .\lambda x^{\alpha }.\lambda f^{\alpha \to \alpha }.x\\1&:=\Lambda \alpha .\lambda x^{\alpha }.\lambda f^{\alpha \to \alpha }.fx\\2&:=\Lambda \alpha .\lambda x^{\alpha }.\lambda f^{\alpha \to \alpha }.f(fx)\\3&:=\Lambda \alpha .\lambda x^{\alpha }.\lambda f^{\alpha \to \alpha }.f(f(fx))\end{aligned}}}

If we reverse the order of the curried arguments (i.e.,α.(αα)αα{\displaystyle \forall \alpha .(\alpha \rightarrow \alpha )\rightarrow \alpha \rightarrow \alpha }), then the Church numeral forn is a function that takes a functionf as argument and returns thenth power off. That is to say, a Church numeral is ahigher-order function – it takes a single-argument functionf, and returns another single-argument function.

Use in programming languages

[edit]

The version of System F used in this article is as an explicitly typed, or Church-style, calculus. The typing information contained in λ-terms makestype-checking straightforward.Joe Wells (1994) settled an "embarrassing open problem" by proving that type checking isundecidable for a Curry-style variant of System F, that is, one that lacks explicit typing annotations.[6][7]

Wells's result implies thattype inference for System F is impossible.A restriction of System F known as "Hindley–Milner", or simply "HM", does have an easy type inference algorithm and is used for manystatically typedfunctional programming languages such asHaskell 98 and theML family. Over time, as the restrictions of HM-style type systems have become apparent, languages have steadily moved to more expressive logics for their type systems.GHC, a Haskell compiler, goes beyond HM (as of 2008) and uses System F extended with non-syntactic type equality;[8] non-HM features inOCaml's type system includeGADT.[9][10]

The Girard–Reynolds isomorphism

[edit]

In second-orderintuitionistic logic, the second-order polymorphic lambda calculus (F2) was discovered by Girard (1972) and independently by Reynolds (1974).[11] Girard proved therepresentation theorem: that in second-order intuitionistic predicate logic (P2), functions from the natural numbers to the natural numbers that can be proved total, form a projection from P2 into F2.[11] Reynolds proved theabstraction theorem: that every term in F2 satisfies a logical relation, which can be embedded into the logical relations P2.[11] Reynolds proved that a Girard projection followed by a Reynolds embedding form the identity, i.e., theGirard–Reynolds isomorphism.[11]

System Fω

[edit]

While System F corresponds to the first axis ofBarendregt'slambda cube,System Fω or thehigher-order polymorphic lambda calculus combines the first axis (polymorphism) with the second axis (type operators); it is a different, more complex system.

System Fω can be defined inductively on a family of systems, where induction is based on thekinds permitted in each system:

In the limit, we can define systemFω{\displaystyle F_{\omega }} to be

That is, Fω is the system which allows functions from types to types where the argument (and result) may be of any order.

Note that although Fω places no restrictions on theorder of the arguments in these mappings, it does restrict theuniverse of the arguments for these mappings: they must be types rather than values. System Fω does not permit mappings from values to types (dependent types), though it does permit mappings from values to values (λ{\displaystyle \lambda } abstraction), mappings from types to values (Λ{\displaystyle \Lambda } abstraction), and mappings from types to types (λ{\displaystyle \lambda } abstraction at the level of types).

System F<:

[edit]

System F<:, pronounced "F-sub", is an extension of system F withsubtyping. System F<: has been of central importance toprogramming language theory since the 1980s because the core offunctional programming languages, like those in theML family, support bothparametric polymorphism andrecord subtyping, which can be expressed inSystem F<:.[12][13]

See also

[edit]

Notes

[edit]
  1. ^Girard, Jean-Yves (1986). "The system F of variable types, fifteen years later".Theoretical Computer Science.45: 160.doi:10.1016/0304-3975(86)90044-7.However, in [3] it was shown that the obvious rules of conversion for this system, called F by chance, were converging.
  2. ^Harper R."Practical Foundations for Programming Languages, Second Edition". pp. 142–3.
  3. ^Geuvers H, Nordström B, Dowek G."Proofs of Programs and Formalisation of Mathematics"(PDF). p. 51.
  4. ^Xavier Leroy, Programming = proving? The Curry-Howard correspondence today, Lectures at College de France, Lecture 2, p. 15, 2018-11-21https://xavierleroy.org/CdF/2018-2019/2.pdf
  5. ^"CS 4110: Programming Languages and Logics - Lecture 26: Existential Types"(PDF).Cornell Ann S. Bowers College of Computing and Information Science. Department of Computer Science, Cornell University. 2018.Archived(PDF) from the original on 2025-09-26. Retrieved2025-11-08.
  6. ^Wells, J.B. (2005-01-20)."Joe Wells's Research Interests". Heriot-Watt University.
  7. ^Wells, J.B. (1999)."Typability and type checking in System F are equivalent and undecidable".Annals of Pure and Applied Logic.98 (1–3):111–156.doi:10.1016/S0168-0072(98)00047-5."The Church Project: Typability and type checking in {S}ystem {F} are equivalent and undecidable". 29 September 2007. Archived fromthe original on 29 September 2007.
  8. ^"System FC: equality constraints and coercions".gitlab.haskell.org. Retrieved2019-07-08.
  9. ^"OCaml 4.00.1 release notes".ocaml.org. 2012-10-05. Retrieved2019-09-23.
  10. ^"OCaml 4.09 reference manual". 2012-09-11. Retrieved2019-09-23.
  11. ^abcdPhilip Wadler (2005)The Girard-Reynolds Isomorphism (second edition)University of Edinburgh,Programming Languages and Foundations at Edinburgh
  12. ^Cardelli, Luca; Martini, Simone; Mitchell, John C.; Scedrov, Andre (1994). "An extension of system F with subtyping".Information and Computation, vol. 9. North Holland, Amsterdam. pp. 4–56.doi:10.1006/inco.1994.1013.
  13. ^Pierce, Benjamin (2002).Types and Programming Languages. MIT Press.ISBN 978-0-262-16209-8., Chapter 26:Bounded quantification

References

[edit]

Further reading

[edit]

External links

[edit]
Wikibooks has a book on the topic of:Haskell
Retrieved from "https://en.wikipedia.org/w/index.php?title=System_F&oldid=1337211146#System_F<:"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp