ArticleslgStudy

computer science

System F

System F is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand System F rather than just read about it. In short: 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.

Key takeaways

  • System F belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect System F to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of System F from memory before moving on to harder problems.

Reference excerpt

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 statement

⊢Λα.λxα.x:∀α.α→α 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 variable 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 second-order propositional intuitionistic logic. 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 σ,τ are types, α is a type variable, and α type in the context indicates that α is bound. The first rule is that of application, and the second is that of abstraction.

Logic and predicates 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:

𝐓=Λα.λxαλyα.x 𝐅=Λα.λxαλ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 ∀α.α→α→α; 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 𝖡𝗈𝗈𝗅𝖾𝖺𝗇→𝖡𝗈𝗈𝗅𝖾𝖺𝗇→𝖡𝗈𝗈𝗅𝖾𝖺𝗇):

AND=λx𝖡𝗈𝗈𝗅𝖾𝖺𝗇λy𝖡𝗈𝗈𝗅𝖾𝖺𝗇.x𝖡𝗈𝗈𝗅𝖾𝖺𝗇y𝐅OR=λx𝖡𝗈𝗈𝗅𝖾𝖺𝗇λy𝖡𝗈𝗈𝗅𝖾𝖺𝗇.x𝖡𝗈𝗈𝗅𝖾𝖺𝗇𝐓yNOT=λx𝖡𝗈𝗈𝗅𝖾𝖺𝗇.x𝖡𝗈𝗈𝗅𝖾𝖺𝗇𝐅𝐓 Note that in the definitions above, 𝖡𝗈𝗈𝗅𝖾𝖺𝗇 is a type argument to x, specifying that the other two parameters that are given to x 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:

IFTHENELSE=Λα.λx𝖡𝗈𝗈𝗅𝖾𝖺𝗇λyαλzα.xαyz 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:

ISZERO=λn∀α.(α→α)→α→α.n𝖡𝗈𝗈𝗅𝖾𝖺𝗇(λx𝖡𝗈𝗈𝗅𝖾𝖺𝗇.𝐅)𝐓 Furthermore, the existential quantifier (and therefore existential types) can be implemented in system F by the following:

∃X.A=∀Y.(∀X.A→Y)→Y

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. Abstract structures (S) are created using constructors. These are functions typed as:

K1→K2→⋯→S. Recursivity is manifested when S itself appears within one of the types Ki. If you have m of these constructors, you can define the type of S as:

∀α.(K11[α/S]→⋯→α)⋯→(K1m[α/S]→⋯→α)→α For instance, the natural numbers can be defined as an inductive datatype N with constructors

𝑧𝑒𝑟𝑜:N𝑠𝑢𝑐𝑐:N→N 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:

0:=Λα.λxα.λfα→α.x1:=Λα.λxα.λfα→α.fx2:=Λα.λxα.λfα→α.f(fx)3:=Λα.λxα.λfα→α.f(f(fx)) 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 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 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; non-HM features in OCaml's type system include GADT.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with System F

Start with the simplest possible case. Write down what System F claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to System F before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about System F ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of System F

In research
System F appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses System F in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
System F is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1971 in computing, 1974 in computing, Lambda calculus, so understanding it makes those chapters shorter.
In everyday life
Look for System F outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “System F” →

How to study System F in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what System F means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain System F out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is System F in simple terms?

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 theoretic…

Why does System F matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study System F?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on System F.

Tags

  • 1971 in computing
  • 1974 in computing
  • Lambda calculus
  • Logic
  • Polymorphism (computer science)
  • Type theory

Keep exploring