fbpx
Wikipedia

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 AA would be formalized in System F as the judgement

where is a type variable. The upper-case is traditionally used to denote type-level functions, as opposed to the lower-case which is used for value-level functions. (The superscripted means that the bound x is of type ; the expression after the colon is the type of the lambda expression preceding it.)

As a term rewriting system, System F is strongly normalizing. However, type inference 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 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.[1]

Typing rules edit

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

  (1)   (2)

where   are types,   is a type variable, and   in the context indicates that   is bound. The first rule is that of application, and the second is that of abstraction. [2] [3]

Logic and predicates edit

The   type is defined as:  , where   is a type variable. This means:   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 be right-associative.)

The following two definitions for the boolean values   and   are used, extending the definition of Church booleans:

 
 

(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  ; the universal quantifier binding the α corresponds to the Λ binding the alpha in the lambda expression itself. Also, note that   is a convenient shorthand for  , but it is not a symbol of System F itself, but rather a "meta-symbol". Likewise,   and   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.)

Then, with these two  -terms, we can define some logic operators (which are of type  ):

 

Note that in the definitions above,   is a type argument to  , specifying that the other two parameters that are given to   are of type  . As in Church encodings, there is no need for an IFTHENELSE function as one can just use raw  -typed terms as decision functions. However, if one is requested:

 

will do. A predicate is a function which returns a  -typed value. The most fundamental predicate is ISZERO which returns   if and only if its argument is the Church numeral 0:

 

System F structures edit

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

 .

Recursivity is manifested when S itself appears within one of the types  . 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.,  ), then the Church numeral for n is a function that takes a function f as argument and returns the nth power of f. That is to say, a Church numeral is a higher-order function – it takes a single-argument function f, 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 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]

The Girard-Reynolds Isomorphism edit

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]

System Fω edit

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:

  •   permits kinds:
    •   (the kind of types) and
    •   where   and   (the kind of functions from types to types, where the argument type is of a lower order)

In the limit, we can define system   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 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 (  abstraction), mappings from types to values (  abstraction), and mappings from types to types (  abstraction at the level of types).

System F<: edit

System F<:, pronounced "F-sub", is an extension of system F with subtyping. 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<:.[10][11]

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" (PDF). pp. 142–3.
  3. ^ Geuvers H, Nordström B, Dowek G. "Proofs of Programs and Formalisation of Mathematics" (PDF). p. 51.
  4. ^ Wells, J.B. (2005-01-20). "Joe Wells's Research Interests". Heriot-Watt University.
  5. ^ Wells, J.B. (1999). "Typability and type checking in System F are equivalent and undecidable". Ann. Pure Appl. Logic. 98 (1–3): 111–156. doi:10.1016/S0168-0072(98)00047-5.. 29 September 2007. Archived from the original on 29 September 2007.
  6. ^ "System FC: equality constraints and coercions". gitlab.haskell.org. Retrieved 2019-07-08.
  7. ^ "OCaml 4.00.1 release notes". ocaml.org. 2012-10-05. Retrieved 2019-09-23.
  8. ^ "OCaml 4.09 reference manual". 2012-09-11. Retrieved 2019-09-23.
  9. ^ a b c d Philip Wadler (2005) The Girard-Reynolds Isomorphism (second edition) University of Edinburgh, Programming Languages and Foundations at Edinburgh
  10. ^ 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.
  11. ^ Pierce, Benjamin (2002). Types and Programming Languages. MIT Press. ISBN 978-0-262-16209-8., Chapter 26: Bounded quantification

References edit

  • Girard, Jean-Yves (1971). "Une Extension de l'Interpretation de Gödel à l'Analyse, et son Application à l'Élimination des Coupures dans l'Analyse et la Théorie des Types". Proceedings of the Second Scandinavian Logic Symposium. Amsterdam. pp. 63–92. doi:10.1016/S0049-237X(08)70843-7.
  • Girard, Jean-Yves (1972), Interprétation fonctionnelle et élimination des coupures de l'arithmétique d'ordre supérieur (Ph.D. thesis) (in French), Université Paris 7.
  • Reynolds, John (1974). Towards a Theory of Type Structure (PDF).
  • Girard, Jean-Yves; Lafont, Yves; Taylor, Paul (1989). Proofs and Types. Cambridge University Press. ISBN 978-0-521-37181-0.
  • Wells, J. B. (1994). "Typability and type checking in the second-order lambda-calculus are equivalent and undecidable". Proceedings of the 9th Annual IEEE Symposium on Logic in Computer Science (LICS). pp. 176–185. doi:10.1109/LICS.1994.316068. ISBN 0-8186-6310-3. Postscript version

Further reading edit

  • Pierce, Benjamin (2002). "V Polymorphism Ch. 23. Universal Types, Ch. 25. An ML Implementation of System F". Types and Programming Languages. MIT Press. pp. 339–362, 381–388. ISBN 0-262-16209-1.

External links edit

system, electronic, trance, music, artist, ferry, corsten, also, polymorphic, lambda, calculus, second, order, lambda, calculus, typed, lambda, calculus, that, introduces, simply, typed, lambda, calculus, mechanism, universal, quantification, over, types, form. For the electronic trance music artist see Ferry Corsten 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 L a l x a x a a a displaystyle vdash Lambda alpha lambda x alpha x forall alpha alpha to alpha where a displaystyle alpha is a type variable The upper case L displaystyle Lambda is traditionally used to denote type level functions as opposed to the lower case l displaystyle lambda which is used for value level functions The superscripted a displaystyle alpha means that the bound x is of type a displaystyle alpha the expression after the colon is the type of the lambda expression preceding it As a term rewriting system System F is strongly normalizing However type inference 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 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 1 Contents 1 Typing rules 2 Logic and predicates 3 System F structures 4 Use in programming languages 5 The Girard Reynolds Isomorphism 6 System Fw 7 System F lt 8 See also 9 Notes 10 References 11 Further reading 12 External linksTyping rules editThe typing rules of System F are those of simply typed lambda calculus with the addition of the following G M a s G M t s t a displaystyle frac Gamma vdash M mathbin forall alpha sigma Gamma vdash M tau mathbin sigma tau alpha nbsp 1 G a type M s G L a M a s displaystyle frac Gamma alpha text type vdash M mathbin sigma Gamma vdash Lambda alpha M mathbin forall alpha sigma nbsp 2 where s t displaystyle sigma tau nbsp are types a displaystyle alpha nbsp is a type variable and a type displaystyle alpha text type nbsp in the context indicates that a displaystyle alpha nbsp is bound The first rule is that of application and the second is that of abstraction 2 3 Logic and predicates editThe B o o l e a n displaystyle mathsf Boolean nbsp type is defined as a a a a displaystyle forall alpha alpha to alpha to alpha nbsp where a displaystyle alpha nbsp is a type variable This means B o o l e a n displaystyle mathsf Boolean nbsp is the type of all functions which take as input a type a and two expressions of type a and produce as output an expression of type a note that we consider displaystyle to nbsp to be right associative The following two definitions for the boolean values T displaystyle mathbf T nbsp and F displaystyle mathbf F nbsp are used extending the definition of Church booleans T L a l x a l y a x displaystyle mathbf T Lambda alpha lambda x alpha lambda y alpha x nbsp F L a l x a l y a y displaystyle mathbf F Lambda alpha lambda x alpha lambda y alpha y nbsp 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 a a a a displaystyle forall alpha alpha to alpha to alpha nbsp the universal quantifier binding the a corresponds to the L binding the alpha in the lambda expression itself Also note that B o o l e a n displaystyle mathsf Boolean nbsp is a convenient shorthand for a a a a displaystyle forall alpha alpha to alpha to alpha nbsp but it is not a symbol of System F itself but rather a meta symbol Likewise T displaystyle mathbf T nbsp and F displaystyle mathbf F nbsp 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 Then with these two l displaystyle lambda nbsp terms we can define some logic operators which are of type B o o l e a n B o o l e a n B o o l e a n displaystyle mathsf Boolean rightarrow mathsf Boolean rightarrow mathsf Boolean nbsp A N D l x B o o l e a n l y B o o l e a n x B o o l e a n y F O R l x B o o l e a n l y B o o l e a n x B o o l e a n T y N O T l x B o o l e a n x B o o l e a n F T displaystyle begin aligned mathrm AND amp lambda x mathsf Boolean lambda y mathsf Boolean x mathsf Boolean y mathbf F mathrm OR amp lambda x mathsf Boolean lambda y mathsf Boolean x mathsf Boolean mathbf T y mathrm NOT amp lambda x mathsf Boolean x mathsf Boolean mathbf F mathbf T end aligned nbsp Note that in the definitions above B o o l e a n displaystyle mathsf Boolean nbsp is a type argument to x displaystyle x nbsp specifying that the other two parameters that are given to x displaystyle x nbsp are of type B o o l e a n displaystyle mathsf Boolean nbsp As in Church encodings there is no need for an IFTHENELSE function as one can just use raw B o o l e a n displaystyle mathsf Boolean nbsp typed terms as decision functions However if one is requested I F T H E N E L S E L a l x B o o l e a n l y a l z a x a y z displaystyle mathrm IFTHENELSE Lambda alpha lambda x mathsf Boolean lambda y alpha lambda z alpha x alpha yz nbsp will do A predicate is a function which returns a B o o l e a n displaystyle mathsf Boolean nbsp typed value The most fundamental predicate is ISZERO which returns T displaystyle mathbf T nbsp if and only if its argument is the Church numeral 0 I S Z E R O l n a a a a a n B o o l e a n l x B o o l e a n 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 nbsp System F structures editSystem F allows recursive constructions to be embedded in a natural manner related to that in Martin Lof s type theory Abstract structures S are created using constructors These are functions typed as K 1 K 2 S displaystyle K 1 rightarrow K 2 rightarrow dots rightarrow S nbsp Recursivity is manifested when S itself appears within one of the types K i displaystyle K i nbsp If you have m of these constructors you can define the type of S as a K 1 1 a S a K 1 m a S a a 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 nbsp For instance the natural numbers can be defined as an inductive datatype N with constructors z e r o N s u c c N N displaystyle begin aligned mathit zero amp mathrm N mathit succ amp mathrm N rightarrow mathrm N end aligned nbsp The System F type corresponding to this structure is a a a a a displaystyle forall alpha alpha to alpha to alpha to alpha nbsp The terms of this type comprise a typed version of the Church numerals the first few of which are 0 L a l x a l f a a x 1 L a l x a l f a a f x 2 L a l x a l f a a f f x 3 L a l x a l f a a f f f x displaystyle begin aligned 0 amp Lambda alpha lambda x alpha lambda f alpha to alpha x 1 amp Lambda alpha lambda x alpha lambda f alpha to alpha fx 2 amp Lambda alpha lambda x alpha lambda f alpha to alpha f fx 3 amp Lambda alpha lambda x alpha lambda f alpha to alpha f f fx end aligned nbsp If we reverse the order of the curried arguments i e a a a a a displaystyle forall alpha alpha rightarrow alpha rightarrow alpha rightarrow alpha nbsp then the Church numeral for n is a function that takes a function f as argument and returns the n th power of f That is to say a Church numeral is a higher order function it takes a single argument function f and returns another single argument function Use in programming languages editThe version of System F used in this article is as an explicitly typed or Church style calculus The typing information contained in l 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 The Girard Reynolds Isomorphism editIn 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 System Fw editWhile System F corresponds to the first axis of Barendregt s lambda cube System Fw 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 Fw can be defined inductively on a family of systems where induction is based on the kinds permitted in each system F n displaystyle F n nbsp permits kinds displaystyle star nbsp the kind of types and J K displaystyle J Rightarrow K nbsp where J F n 1 displaystyle J in F n 1 nbsp and K F n displaystyle K in F n nbsp 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 w displaystyle F omega nbsp to be F w 1 i F i displaystyle F omega underset 1 leq i bigcup F i nbsp That is Fw is the system which allows functions from types to types where the argument and result may be of any order Note that although Fw 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 Fw does not permit mappings from values to types dependent types though it does permit mappings from values to values l displaystyle lambda nbsp abstraction mappings from types to values L displaystyle Lambda nbsp abstraction and mappings from types to types l displaystyle lambda nbsp abstraction at the level of types System F lt editSystem F lt pronounced F sub is an extension of system F with subtyping System F lt 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 lt 10 11 See also editExistential types the existentially quantified counterparts of universal types System UNotes edit 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 Harper R Practical Foundations for Programming Languages Second Edition PDF pp 142 3 Geuvers H Nordstrom B Dowek G Proofs of Programs and Formalisation of Mathematics PDF p 51 Wells J B 2005 01 20 Joe Wells s Research Interests Heriot Watt University Wells J B 1999 Typability and type checking in System F are equivalent and undecidable Ann Pure Appl 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 from the original on 29 September 2007 System FC equality constraints and coercions gitlab haskell org Retrieved 2019 07 08 OCaml 4 00 1 release notes ocaml org 2012 10 05 Retrieved 2019 09 23 OCaml 4 09 reference manual 2012 09 11 Retrieved 2019 09 23 a b c d Philip Wadler 2005 The Girard Reynolds Isomorphism second edition University of Edinburgh Programming Languages and Foundations at Edinburgh 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 Pierce Benjamin 2002 Types and Programming Languages MIT Press ISBN 978 0 262 16209 8 Chapter 26 Bounded quantificationReferences editGirard Jean Yves 1971 Une Extension de l Interpretation de Godel a l Analyse et son Application a l Elimination des Coupures dans l Analyse et la Theorie des Types Proceedings of the Second Scandinavian Logic Symposium Amsterdam pp 63 92 doi 10 1016 S0049 237X 08 70843 7 Girard Jean Yves 1972 Interpretation fonctionnelle et elimination des coupures de l arithmetique d ordre superieur Ph D thesis in French Universite Paris 7 Reynolds John 1974 Towards a Theory of Type Structure PDF Girard Jean Yves Lafont Yves Taylor Paul 1989 Proofs and Types Cambridge University Press ISBN 978 0 521 37181 0 Wells J B 1994 Typability and type checking in the second order lambda calculus are equivalent and undecidable Proceedings of the 9th Annual IEEE Symposium on Logic in Computer Science LICS pp 176 185 doi 10 1109 LICS 1994 316068 ISBN 0 8186 6310 3 Postscript versionFurther reading editPierce Benjamin 2002 V Polymorphism Ch 23 Universal Types Ch 25 An ML Implementation of System F Types and Programming Languages MIT Press pp 339 362 381 388 ISBN 0 262 16209 1 External links edit nbsp Wikibooks has a book on the topic of Haskell Summary of System F by Franck Binard System Fw the workhorse of modern compilers by Greg Morrisett Retrieved from https en wikipedia org w index php title System F amp oldid 1219974721, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.