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 polymorphism in programming languages, thus forming a theoretical basis for languages such as Haskell and ML.

It was discovered independently by logician Jean-Yves Girard (1972) and computer scientist John C. Reynolds.

Whereas simply typed lambda calculus has variables ranging over terms, and binders for them, System F additionally has variables ranging over types, and binders for them.

As an example, the fact that the identity function can have any type of the form A → A would be formalized in System F as the judgement where

is traditionally used to denote type-level functions, as opposed to the lower-case

Under the Curry–Howard isomorphism, System F corresponds to the fragment of second-order intuitionistic logic that uses only universal quantification.

System F can be seen as part of the lambda cube, together with even more expressive typed lambda calculi, including those with dependent types.

are used, extending the definition of Church booleans: (Note that the above two functions require three — not two — arguments.

; the universal quantifier binding the α corresponds to the Λ binding the alpha in the lambda expression itself.

are also "meta-symbols", convenient shorthands, of System F "assemblies" (in the Bourbaki 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 the fixed-point combinator, which works around that restriction.)

As in Church encodings, there is no need for an IFTHENELSE function as one can just use raw

if and only if its argument is the Church numeral 0: System F allows recursive constructions to be embedded in a natural manner, related to that in Martin-Löf's type theory.

If you have m of these constructors, you can define the type of S as: For instance, the natural numbers can be defined as an inductive datatype N with constructors The System F type corresponding to this structure is

The terms of this type comprise a typed version of the Church numerals, the first few of which are: If we reverse the order of the curried arguments (i.e.,

The version of System F used in this article is as an explicitly typed, or Church-style, calculus.

The typing information contained in λ-terms makes type-checking straightforward.

Joe Wells (1994) settled an "embarrassing open problem" by proving that type checking is undecidable for a Curry-style variant of System F, that is, one that lacks explicit typing annotations.

[4][5] Wells's result implies that type 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 many statically typed functional programming languages such as Haskell 98 and the ML 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;[6] non-HM features in OCaml's type system include GADT.

[7][8] In second-order intuitionistic logic, the second-order polymorphic lambda calculus (F2) was discovered by Girard (1972) and independently by Reynolds (1974).

[9] Girard proved the Representation 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.

[9] Reynolds proved the Abstraction Theorem: that every term in F2 satisfies a logical relation, which can be embedded into the logical relations P2.

[9] Reynolds proved that a Girard projection followed by a Reynolds embedding form the identity, i.e., the Girard-Reynolds Isomorphism.

[9] While System F corresponds to the first axis of Barendregt's lambda cube, System Fω or the higher-order polymorphic lambda calculus combines the first axis (polymorphism) with the second axis (type operators); it is a different, more complex system.

Note that although Fω places no restrictions on the order of the arguments in these mappings, it does restrict the universe of the arguments for these mappings: they must be types rather than values.

abstraction), mappings from types to values (

System F<: has been of central importance to programming language theory since the 1980s[citation needed] because the core of functional programming languages, like those in the ML family, support both parametric polymorphism and record subtyping, which can be expressed in System F<:.