System F
System F is a type system historically developed independently by Jean-Yves Girard and John Reynolds. It enriches simply typed lambda calculus with an impredicative universal quantifier over types.
Logically, it corresponds to second order minimal logic, that is, a second order logic without first-order quantifiers. The idea of having second order quantifications, but not first order ones, stems from the observation that first order quantiication doesnβt have a clear computational interpretation.
Definition
Let us define inductively types as follows
then terms
We define straightforwardly the typing judgement
Encodings
Impredicative encodings are extremely powerful, as they are enough to define a large class of inductive types with their plain recursor.
The trick is to encode a type as the type of (polymorphic) recursors. Thus, encodings are similar to Church encodings in plain -calculus.
It should be noted that, although these encodings are logically enough to be as expressive as inductive types, they are computationally bad encodings, in the sense that they are very wasteful. Natural numbers, for instance, end up being represented in a unary form that additionally has extra overhead than plain unary numbers.
Empty type
The empty type is encoded as
Indeed, if I have a term , and any type , one can derive a witness of , which makes validate the ex falso quodlibet principle.
Unit type
The unit type is encoded as
as well as having a constructor
We will prove that every closed value has the canonicity property:
This will stem from a more general adequacy result.
Natural numbers
Natural numbers are encoded as
with
Product type
Let , be two types. We can define
and, for and , we have
Sum type
Let , be two types. We can define
and
Existential type
Let be a type, we can define
Meta-theoretic properties
Meta-properties of System F are mainly established through two ways.
Firstly, by reduction to -calculus: System F introduces type binders and application, but thatβs an extremely tame calculus because it
- doesnβt interfere with itself: reducing a redex cannot create an other similar redex
- doesnβt interfere with the standard reduction: reducing a redex as above cannot create a redex
Hence one can essentially erase all the second order part from a System F term to retrieve important properties of the -calculus, such as confluence.
Secondly, by crafting adequate logical relations, as with STLC. Note, however, that historically this second part has been considered a hard problem, because System Fβs impredicativity breaks the naive way to make logical relations. Indeed, System Fβs strong normalisation (which follows directly from being able to define logical relations) need the meta theory to itself have impredicativity, and it cannot be proved, for instance, in MLTT.
Logical relations
For this section, let be a natural number, which is a parameter of our logical relation construction. will define the arity of the logical relation. Common values are .
We will define, by induction on , an -ary relation , where , and is a family of -ary relations on values of System F, used to interpret free variables of .
where
Note that, crucially, the interpretation of a universal type requires an impredicative universal quantification in the meta-theory.
Theorem Fundamental theorem of logical relations Let be a type with free variables in , and such that . For any environment , it holds that
Proof.
By induction on :
- .
Strong normalisation
Decidability problems
System F is a simple extension of previewSTLC, that is expressive enough to be used as a programming language: for instance, the core type system of OCaml is a subset of System F.
Yet, System F is not used for programming languages in practice, because of a fundamental limitation:
Type checking
The precise statement of the theorem is: for a term, and a type, it is undecidable to know whether
Type inference
For a term, it is undecidable whether there exists a type such that
Mitigation
Undecidability of System F can be mitigated using an intrinsic presentation of its calculus, rather than an extrinsic one.
However, even intrinsic System F is rarely used in practice, because programming languages that abandon decidable type checking (and thus, in the general case, need user annotations) usually go for even more expressive type theories, for instance with higher kinded types (see System F), or even with full type dependency (see the Calculus of Constructions).