Scarlet Serenade

Types and Programming Languages | System F

Idea: lambda abstraction over type variables, defining functions over types.


System F (also known as the polymorphic lambda calculus) = + parametric polymorphism.

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

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.)

Environment rules for

Kinding rules for

System F extends with a type-level operator − that binds a variable within a particular scope.

There are two new kinding rules:

The rule builds universal types

The tyvar rule is a type-level analogue of the tvar rule: it allows type variables to appear within type expressions, making it possible to build open types (i.e. types with free variables).

These rules involve a new kind of variable into the language. Type variables are bound by and (as we shall see) by , and can be used in place of concrete types in expressions.

Typing rules for

Since we have a new type constructor , we need a new pair of introduction and elimination rules:

The rule shows how to build values of type — that is, polymorphic values.

The rule shows how to use values of polymorphic type via a second form of application: applying a (suitably-typed) term to a type.

Extensions

Adding Existentials

A value of type is a package with a witness type for and a value term

It turns out that there is indeed a useful notion of types: just as is used for terms which can be instantiated at any type, can be used to form types for which we have some implementation, but prefer to leave the details abstract.

In fact, it is possible to encode existential types using universal types. But for the time being, will find it more convenient to introduce them directly as an extension to System F.

Kinding rules for

Typing rules for

The rule shows how to build values of existential type using a new construct, pack.

The rule shows how to use values of existential type using a new construct open

Encoding data types in System F