The Typed Polymorphic -Calculus
Keywords: main

Next: A Transportation Model in Up: Technical Background Previous: Monoids

##
The Typed Polymorphic -Calculus

We assume a set of pregiven constants ususally denoted by , and a countably infinite set of variable symbols usually denoted by . The syntax of a term t of the -Calculus is given by the following grammar:

| (8)

We shall call the set of terms t defined by this grammar. These terms are also called raw terms.

An abstraction defines a lexical scope for its bound variable x, whose extent is its body t. Thus, the notion of free occurrence of a variable in a term is defined as usual, and so is the operation t1[t2/x] of substituting a term t2 for all the free occurrences of a variable x in a term t1. Thus, a bound variable may be renamed to a new one in its scope without changing the abstraction.

The computation rule defined on -terms is the so-called -reduction:

| (9)

We assume a set of basic type symbols denoted by , and a countably infinite set of type variables denoted by . The syntax of a type of the Typed Polymorphic -Calculus is given by the following grammar:

| (10)

We shall call the set of types defined by this grammar. A monomorphic type is a type that contains no variable types. Any type containing at least one variable type is called a polymorphic type.

The terms of the Typed Polymorphic -Calculus are only those raw terms in that admit a well-defined type in . Each constant in is assumed to have a unique type in , and we write to mean that constant a has type .

One may assign types to symbols using a type context , which is a partial function from V to . Given a type context , a variable and a type , we define:

| (11)

In other words, coincides with everywhere on except at x, where it takes the value . The empty context is the function noted defined nowhere on .

To find out whether a term t in is well-typed, one must exhibit a type assignment that constitutes a suitable typing context for the variable symbols occurring in t, and from which one may ascribe a (unique) type for the whole term. Given a type context , a term t, and a type , a type judgement is an expression of the form , which stands to mean that t has been deemed to have type when the symbols occurring in it have the types assigned to them by the context . Without a type context , the expression is used to mean that for some .

Deriving types for terms is done using typing rules of the form:

which is read as follows: ``t has type under if t1 has type under , ..., and tn has type under .'' Note that it is possible that n=0, in which case the rule is written:

and it is called an axiom.

The typing rules for the Typed Polymorphic -Calculus are given in Figure 4.

Figure: Typing rules for the Typed Polymorphic -Calculus

These rules can be readily translated into a Logic Programming language based on Horn-clauses such as Prolog, and used as an effective means to infer the types of expressions based on the Typed Polymorphic -Calculus.

The basic syntax of the Typed Polymorphic -Calculus may be extended with other operators and convenient data structures as long as typing rules for the new constructs are provided. Typically, one provides at least the set of integer constants and of boolean constants, along with basic arithmetic and boolean operators, pairing (or tupling), a conditional operator, and a fix-point operator. The usual arithmetic and boolean operators are denoted by constant symbols (e.g., etc.). Let be this set.

The computation rules for these operators are based on their usual semantics as one might expect, modulo transforming the usual binary infix notation to a ``curryed'' application. For example, t1+t2is implicitly taken to be the application . Note that this means that all such operators are implicitly ``curryed.''7

For example, we may augment the grammar for the terms given in (8) as follows:

| (12)

The computation rules for the other new constructs are:

| (13)

To account for the new constructs, the syntax of types is extended accordingly to:

| (14)

We are given that for all and that and . The (fully curried) types of the built-in operators are given similarly; i.e., , , etc., ...The typing rules for this extended calculus are given in Figure 5.

Figure: Typing rules for an Extended Typed Polymorphic -Calculus

Next: A Transportation Model in Up: Technical Background Previous: Monoids