System F-omega
   HOME

TheInfoList



OR:

System F (also polymorphic lambda calculus or second-order lambda calculus) is a
typed lambda calculus A typed lambda calculus is a typed formalism that uses the lambda symbol (\lambda) to denote anonymous function abstraction. In this context, types are usually objects of a syntactic nature that are assigned to lambda terms; the exact nature of a ...
that introduces, to
simply typed lambda calculus 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 ...
, a mechanism of
universal quantification In mathematical logic, a universal quantification is a type of quantifier, a logical constant which is interpreted as "given any", "for all", "for every", or "given an arbitrary element". It expresses that a predicate can be satisfied by e ...
over types. System F formalizes
parametric polymorphism In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorph ...
in
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s, thus forming a theoretical basis for languages such as
Haskell Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...
and ML. It was discovered independently by
logician Logic is the study of correct reasoning. It includes both formal and informal logic. Formal logic is the study of deductively valid inferences or logical truths. It examines how conclusions follow from premises based on the structure of arg ...
Jean-Yves Girard Jean-Yves Girard (; born 1947) is a French logician working in proof theory. He is a research director (emeritus) at the mathematical institute of University of Aix-Marseille, at Luminy. Biography Jean-Yves Girard is an alumnus of the Éc ...
(1972) and
computer scientist A computer scientist is a scientist who specializes in the academic study of computer science. Computer scientists typically work on the theoretical side of computation. Although computer scientists can also focus their work and research on ...
John C. Reynolds John Charles Reynolds (June 1, 1935 – April 28, 2013) was an American computer scientist. Education and affiliations John Reynolds studied at Purdue University and then earned a Doctor of Philosophy (Ph.D.) in theoretical physics from Harvard U ...
. Whereas
simply typed lambda calculus 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 ...
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 :\vdash \Lambda\alpha. \lambda x^\alpha.x: \forall\alpha.\alpha \to \alpha where \alpha is a
type variable In type theory and programming languages, a type variable is a mathematical variable ranging over types. Even in programming languages that allow mutable variables, a type variable remains an abstraction, in the sense that it does not correspond ...
. The upper-case \Lambda is traditionally used to denote type-level functions, as opposed to the lower-case \lambda which is used for value-level functions. (The superscripted \alpha means that the bound variable ''x'' is of type \alpha; the expression after the colon is the type of the lambda expression preceding it.) As a
term rewriting system In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
, System F is strongly normalizing. However,
type inference Type inference, sometimes called type reconstruction, 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 bran ...
in System F (without explicit type annotations) is undecidable. Under the Curry–Howard isomorphism, System F corresponds to the fragment of second-order
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 ...
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. According to Girard, the "F" in ''System F'' was picked by chance.


Typing rules

The typing rules of System F are those of simply typed lambda calculus with the addition of the following: where \sigma, \tau are types, \alpha is a type variable, and \alpha~\text in the context indicates that \alpha is bound. The first rule is that of application, and the second is that of abstraction.


Logic and predicates

The \mathsf type is defined as: \forall\alpha.\alpha \to \alpha \to \alpha, where \alpha is a
type variable In type theory and programming languages, a type variable is a mathematical variable ranging over types. Even in programming languages that allow mutable variables, a type variable remains an abstraction, in the sense that it does not correspond ...
. This means: \mathsf 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 \to to be
right-associative In programming language theory, the associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. If an operand is both preceded and followed by operators (for examp ...
.) The following two definitions for the boolean values \mathbf and \mathbf are used, extending the definition of Church booleans: : \mathbf = \Lambda\alpha\lambda x^ \lambda y^\alphax : \mathbf = \Lambda\alpha\lambda x^ \lambda y^y (Note that the above two functions require ''three'' — 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 \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 that \mathsf is a convenient shorthand for \forall\alpha.\alpha \to \alpha \to \alpha, but it is not a symbol of System F itself, but rather a "meta-symbol". Likewise, \mathbf and \mathbf are also "meta-symbols", convenient shorthands, of System F "assemblies" (in th
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 In combinatory logic for computer science, a fixed-point combinator (or fixpoint combinator) is a higher-order function (i.e., a function which takes a function as argument) that returns some '' fixed point'' (a value that is mapped to itself) of ...
, which works around that restriction.) Then, with these two \lambda-terms, we can define some logic operators (which are of type \mathsf \rightarrow \mathsf \rightarrow \mathsf): : \begin \mathrm &= \lambda x^ \lambda y^ x \, \mathsf \, y\, \mathbf\\ \mathrm &= \lambda x^ \lambda y^ x \, \mathsf \, \mathbf\, y\\ \mathrm &= \lambda x^ x \, \mathsf \, \mathbf\, \mathbf \end Note that in the definitions above, \mathsf is a type argument to x, specifying that the other two parameters that are given to x are of type \mathsf. As in Church encodings, there is no need for an function as one can just use raw \mathsf-typed terms as decision functions. However, if one is requested: : \mathrm = \Lambda \alpha.\lambda x^\lambda y^\lambda z^. x \alpha y z will do. A ''predicate'' is a function which returns a \mathsf-typed value. The most fundamental predicate is which returns \mathbf if and only if its argument is the Church numeral : : \mathrm = \lambda n^n \, \mathsf \, (\lambda x^\mathbf)\, \mathbf


System F structures

System F allows recursive constructions to be embedded in a natural manner, related to that in
Martin-Löf's type theory Intuitionistic type theory (also known as constructive type theory, or Martin-Löf type theory (MLTT)) is a type theory and an alternative foundation of mathematics. Intuitionistic type theory was created by Per Martin-Löf, a Swedish mathematicia ...
. Abstract structures () are created using ''constructors''. These are functions typed as: :K_1\rightarrow K_2\rightarrow\dots\rightarrow S. Recursivity is manifested when itself appears within one of the types K_i. If you have of these constructors, you can define the type of as: :\forall \alpha.(K_1^1 alpha/Srightarrow\dots\rightarrow \alpha)\dots\rightarrow(K_1^m alpha/Srightarrow\dots\rightarrow \alpha)\rightarrow \alpha For instance, the natural numbers can be defined as an inductive datatype with constructors : \begin \mathit &: \mathrm\\ \mathit &: \mathrm \rightarrow \mathrm \end The System F type corresponding to this structure is \forall \alpha. \alpha \to (\alpha \to \alpha) \to \alpha. The terms of this type comprise a typed version of the Church numerals, the first few of which are: : \begin 0 &:= \Lambda \alpha . \lambda x^\alpha . \lambda f^ . x\\ 1 &:= \Lambda \alpha . \lambda x^\alpha . \lambda f^ . f x\\ 2 &:= \Lambda \alpha . \lambda x^\alpha . \lambda f^ . f (f x)\\ 3 &:= \Lambda \alpha . \lambda x^\alpha . \lambda f^ . f (f (f x)) \end If we reverse the order of the curried arguments (''i.e.,'' \forall \alpha. (\alpha \rightarrow \alpha) \rightarrow \alpha \rightarrow \alpha), then the Church numeral for is a function that takes a function as argument and returns the th power of . That is to say, a Church numeral is a
higher-order function In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself ...
– it takes a single-argument function , and returns another single-argument function.


Use in programming languages

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. Wells's result implies that
type inference Type inference, sometimes called type reconstruction, 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 bran ...
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 In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
functional programming languages In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map ...
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; non-HM features in
OCaml OCaml ( , formerly Objective Caml) is a General-purpose programming language, general-purpose, High-level programming language, high-level, Comparison of multi-paradigm programming languages, multi-paradigm programming language which extends the ...
's type system include GADT.


The Girard-Reynolds Isomorphism

In second-order
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 ...
, the second-order polymorphic lambda calculus (F2) was discovered by Girard (1972) and independently by Reynolds (1974). 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. Reynolds proved the ''Abstraction Theorem'': that every term in F2 satisfies a logical relation, which can be embedded into the logical relations P2. Reynolds proved that a Girard projection followed by a Reynolds embedding form the identity, i.e., the Girard-Reynolds Isomorphism. Philip Wadler (2005
The Girard-Reynolds Isomorphism (second edition)
University of Edinburgh The University of Edinburgh (, ; abbreviated as ''Edin.'' in Post-nominal letters, post-nominals) is a Public university, public research university based in Edinburgh, Scotland. Founded by the City of Edinburgh Council, town council under th ...

Programming Languages and Foundations at Edinburgh
/ref>


System Fω

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. System Fω can be defined inductively on a family of systems, where induction is based on the kinds permitted in each system: * F_n permits kinds: ** \star (the kind of types) and ** J\Rightarrow K where J\in F_ and K\in F_n (the kind of functions from types to types, where the argument type is of a lower order) In the limit, we can define system F_\omega to be * F_\omega = \underset F_i 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 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. System Fω does not permit mappings from values to types ( dependent types), though it does permit mappings from values to values (\lambda abstraction), mappings from types to values (\Lambda abstraction), and mappings from types to types (\lambda abstraction at the level of types).


System F<:

System F<:, pronounced "F-sub", is an extension of system F with
subtyping In programming language theory, subtyping (also called subtype polymorphism or inclusion polymorphism) is a form of type polymorphism. A ''subtype'' is a datatype that is related to another datatype (the ''supertype'') by some notion of substi ...
. System F<: has been of central importance to
programming language theory Programming language theory (PLT) is a branch of computer science that deals with the design, implementation, analysis, characterization, and classification of formal languages known as programming languages. Programming language theory is clos ...
since the 1980s because the core of
functional programming languages In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map ...
, like those in the ML family, support both
parametric polymorphism In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorph ...
and record subtyping, which can be expressed in System F<:., Chapter 26: Bounded quantification


See also

* Existential types — the existentially quantified counterparts of universal types *
System U In mathematical logic, System U and System U− are pure type systems, i.e. special forms of a typed lambda calculus with an arbitrary number of sorts, axioms and rules (or dependencies between the sorts). System U was proved inconsistent by Je ...
* Lambda cube


Notes


References

* * . * *
Postscript version


Further reading

*


External links

{{Wikibooks, Haskell
Summary of System F
by Franck Binard.
System Fω: the workhorse of modern compilers
by Greg Morrisett 1971 in computing 1974 in computing Lambda calculus Type theory Polymorphism (computer science) Logic