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
of the
-Calculus is given by the following grammar:
An abstraction
defines a lexical scope for its
bound variable
, whose extent is its body
. Thus, the notion of free occurrence of a variable in a term is
defined as usual, and so is the operation
of
substituting a term
for all the free occurrences of a variable
in a term
. 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:
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:
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
has type
.
One may assign types to symbols using a type context
, which is a partial function from
to
. Given a
type context
, a variable
and a type
,
we define:
To find out whether a term
in
is well-typed, one must
exhibit a type assignment that constitutes a suitable typing context
for the variable symbols occurring in
, and from which one may
ascribe a (unique) type for the whole term. Given a type context
, a term
, and a type
, a type judgement is
an expression of the form
, which stands
to mean that
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:
The typing rules for the Typed Polymorphic
-Calculus are
given in Figure 4.
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,
is 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:
The computation rules for the other new constructs are:
To account for the new constructs, the syntax of types is extended accordingly to:
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.