Intersection Type Assignment Systems

Steffen van Bakel

Afdeling Informatica, Universiteit Nijmegen, Toernooiveld 1, 6525 ED Nijmegen, Nederland. [email protected]

Abstract

This paper gives an overview of intersection type assignment for the Lambda Calculus, as well as compare in detail variants that have been de®ned in the past. It presents the essential intersection type assignment system, that will prove to be as powerful as the well-known BCD-system. It is essential in the following sense: it is an almost syntax directed system that satis®es all major properties of the BCD- system, and the types used are the representatives of equivalence classes of types in the BCD-system. The of typeable terms can be characterized in the same way, the system is complete with respect to the simple type semantics, and it has the principal type property.

Introduction

In the recent years several notions of type assignment for several (extended) lambda calculi have been studied. The oldest among these is a well understood and elegantly de®ned notion of type assignment on lambda terms, known as the Curry type assignment system [14]. It expresses abstraction and application, and can be used to obtain a (basic) functional characterization of

terms. It is well known that in that system, the problem of typeability

B B M Given a term M , is there a basis and a type such that : ? is decidable, and that it has the principal type property. These two properties found their way into programming, mainly through the pioneering work of R. Milner [28]. He introduced a language ML, of which the underlying is an extension of Curry's system. The extension consists of the introduction of polymorphic functions, i.e. functions that can be applied to various kinds of arguments, even of incomparable type. The formal motivation of this concept lies directly in the notion of principal types. Though the Curry system is already powerful and convenient for use in programming practice,

it has drawbacks. It is, for example, not possible to assign a type to the term ( xxx), and terms

that are -equal can have different principal type schemes. The Intersection Type Discipline as presented in [10] by M. Coppo, M. Dezani-Ciancaglini, and B. Venneri (a more enhanced system was presented in [6] by H. Barendregt, M. Coppo, and M. Dezani-Ciancaglini) is an extension of Curry's system that does not have these drawbacks. The extension being made consists mainly of allowing for term variables (and terms) to have more than one type. Intersection types are

constructed by adding, next to the ` ' of Curry's system, the type constructor `' and the type constant ` '. This slight generalization causes a great change in complexity; in fact, now all terms having a (head) normal form can be characterized by their assignable types, a

 Supported by the Netherlands Organisation for the advancement of pure research (N.W.O.). Current af®liation: Diparti- mento di Informatica, UniversitaÁ degli Studi di Torino, Corso Svizzera 185, 10149 Torino, Italia, [email protected]

1 property that immediately shows that type assignment (even in the system that does not contain

, see [1]) is undecidable. Also, by introducing this extension a system is obtained that is closed

B M M B N N under -equality: if : and = , then : .

The type assignment system presented in [6] (the BCD-system) is based on the system as

T

presented in [10]. It de®nes the set of intersection types in a more general way by treating ` ' as a general type constructor, and introduces two derivation rules for introduction and elimination of intersections; the handling of intersection in this way is inspired by the similarity between intersection and logical conjunction. A big contribution of [6] to the theory of intersection types is

the introduction of a ®lter -model and the proof of completeness of type assignment; to achieve

the latter, the system is strengthened further by introducing a partial order relation ` ' on types as

well as adding the type assignment rule ( ). A disadvantage of the BCD-system is that type assignment in this system is undecidable. In recent years, some decidable restrictions have been studied. The ®rst was the Rank2 intersection type assignment system [2], as ®rst suggested by D. Leivant in [26], that is very close to the notion

of type assignment as used in ML. The key idea for this system is to restrict the set of types to those

n of the shape (( 1 n ) ), where the 1 are types that do not contain intersections. This Rank 2 system was later used as a basis for the notion of type assignment as studied by M. Coppo and P. Giannini in [12]. In that paper the idea behind the let-construct of ML is generalized. In ML, quanti®cation of type-variables is introduced, with the normal restriction that a term variable can only be bound if it does not occur free in the basis (context) for a term; only those type-variables can be instantiated by types. Similarly in [12], only those type-variables can be expanded (for the notion of expansion, see Subsection 5.1). Since the operation of expansion uses also the notion of quanti®cation, intersection types in this system are limited to those that have the same shape, instead of allowing for arbitrary intersections. The system studied by F. Damiani

and P. Giannini in [15] is a restriction of the system in [12], in that an (I)-step can only be performed against the types actually used for the term-variable; the notion of type assignment of that paper is, therefore, called relevant. That intersection types can be used as a basis for programming languages was ®rst discussed by J. Reynolds in [32]. This led to the development of the (typed) programming language Forsythe [33], and to the work of B.C. Pierce [30,31], who studied intersection types and bounded polymor- phism in the ®eld of typed lambda calculi. Because there only typed systems are considered, the systems are decidable.

Another disadvantage of the BCD-system is that it is too general: in this system there are several ways to deduce a desired result, due to the presence of the derivation rules ( I), ( E) and

(). These rules not only allow of super¯uous steps in derivations, but also make it possible to

give essentially different derivations for the same result. Moreover, in [6] the relation induced

an equivalence relation on types. Equivalence classes are big (for example: ( ), for all types ) and type assignment is closed for . The BCD-system has the principal type property, as was shown in [34]; the set of operations

needed for this system consists of substitutions, expansions, and rises; although for every M the

B i j B M g set fh : can be generated using those operations speci®ed in [34], the problem of

type-checking

B B M Given a term M and type , is there a basis such that : ?

2 is complicated. This is not only due to the undecidability of the problem, but even a semi-algorithm is dif®cult to de®ne, due to the equivalence relation. Moreover, because of the general treatment of intersection types, the sequence of operations needed to go from one type to another is normally not unique. The Essential Type Assignment System as presented in this paper is a true restriction of the BCD-system that satis®es all properties of that system, and is also an extension of Curry's system. It will be shown that, in order to prove a completeness result using intersection types, there is no need to be as general as in [6]; this result can also be obtained for the essential system. The main advantage of the essential system over the BCD-system is that the set of types assignable to a term is signi®cantly smaller. An other advantage of the essential system is that derivations are syntax-directed: there is, unlike in the BCD-system, a one-one relationship between terms and skeletons of derivations. These two features are supported by a less complicated type structure. The system presented here is also an extension of the strict type assignment system as presented

in [1]. The major difference is that the essential system will prove to be closed for -reduction: If

B M M N B N E : and , then E : . This does not hold for the strict system. This paper also gives an overview of various notions of intersection type assignment, in order to give insight and intuition, and to compare in detail the various systems and their development. The main objective of this paper is to show that the treatment of intersection types as in [6] has been too general; the same results could have been obtained for a far less complicated system,

that follows more closely the syntactical structure of terms, and treats the type not as a type constant, but as the empty intersection. Great advantages of this approach are a less complicated type language, less complicated proofs, and more precise and elegant de®nitions. For example, the operations that are de®ned in this paper, needed in a proof for the principal type property are `orthogonal': there is no overlap. Also, some results already known for, for example, the BCD-system orone of the CDV-systems

will be shown to hold for the essential system ( E ).

B M M N B N

If E : and , then E : .

B M M B N N

If E : and = , then E : .

B M M

E : and = , if and only if has a head normal form.

B M B M

E : and does not occur in and , if and only if has a normal form. E has the principal type property. In general, this will be done using different techniques like, for example, for Theorems 2.8, 2.10, 3.2.7, and 3.3.2; the proof of Theorem 6.3.3 uses a standard technique, but is based on new ideas. The outline of this paper is as follows. Section 1 will give an overview of, in total, ®ve notions of intersection type assignment, that will be compared and discussed. Subsection 1.1 presents the Coppo-Dezani system as de®ned in [7], Subsection 1.2 presents two Coppo-Dezani-Venneri systems as ®rst de®ned in [10], Subsection 1.3 presents the Barendregt-Coppo-Dezani system that can be found in [6], and Subsection 1.4 presents the strict system of [1]. Section 2 contains the presentation of the essential type assignment system, an extension of the strict system, and a restriction of the BCD-system that will prove to be equally powerful as

the BCD-system. In that subsection it will be shown that type assignment in this system is closed for -equality (Theorem 2.10) and -reduction (Theorem 2.8). In Section 3 an approximation

3

M A A M B A theorem will be proved: B E : ( )[ E : ] (Theorem 3.2.7), using a notion of computability. With this result, a characterization of the sets of terms having a (head) normal form will be given (Theorem 3.3.2). In Section 4, soundness and completeness of essential type assignment will be proved (respectively in Theorem 4.3.1 and Theorem 4.3.6). The section starts with formulating the relation between the BCD- and the essential system in Subsection 4.1. In

Subsection 4.2 a ®lter -model will be de®ned, that is used in Subsection 4.3 to prove completeness of type assignment with respect to the simple type semantics (see De®nition 1.3.5). For three of these systems presented in the past (one CDV system, the BCD system and the strict system) the principal type property has been shown to hold in, respectively, [9], [34], and [4]; in Section 5 the constructions of the proofs of the various papers will be discussed. Finally, in Section 6, the proof for the principal type property for the essential system will be sketched. The results presented in this paper ®rst appeared, in a condensed and slightly different form, in [3].

Notations

In this paper, the symbol will be a type-variable; Greek symbols like , , , , , and will

range over types, and will be used for principal types. ` ' will be assumed to associate to the

M N x y z

right, and ` ' binds stronger than ` '. , are used for lambda terms, , , for term-variables,

N x A B

M [ ] for the usual operation of substitution in terms, and for terms in -normal form. is

n x B x used for bases, B for the basis obtained from by erasing the statement that has as subject,

and P for principal bases. All symbols can appear indexed. Two types (bases, pairs of basis and type) are disjoint if and only if they have no type-variables

in common. Notions of type assignment are de®ned as ternary relations on bases, terms, and types, M

that are denoted by , possibly indexed if necessary. If in a notion of type assignment for there

B M M M are basis B and type such that : , then is typed with , and is assigned to .

1 A historical perspective

Type assignment for the Lambda Calculus was ®rst studied by H.B. Curry in [13]. (See also [14].) Curry's system ± the ®rst and most primitive one ± expresses abstraction and application and its major advantage is that the problem of type assignment is decidable. The types used in this system

are those obtained from type-variables and the type-constructor `arrow'.

De®nition 1.1 i) The set of Curry-types is inductively de®ned by:

a) All type-variables 0, 1, are Curry-types.

b) If and are Curry-types, then so is .

ii) Curry-type assignment and Curry-derivations are de®ned by the following natural deduction system.

4 [x: ]

:

N

M : : M : (E):

(I): (a)

MN :

xM :

x M (a) If x: is the only statement about on which : depends.

The main results proved for this system are:

M hP i P M

The principal type property: for every typeable there is a pair , such that: : ,

B i B M hP i

and for every pair h such that : , there exists a substitution Sub such that Sub ( )

B i = h .

Decidability of type assignment.

Strongly normalizability of all typeable terms.

Curry's system has drawbacks: it is for example not possible to assign a type to the lambda

cdd xy z xz y z aba

term ( xxx), and although the lambda terms ( ) and (( ( ))( )) are -equal,

the principal type schemes for these terms are different, 0 1 1 and ( 1 0) 1 1, respectively. The Intersection Type Discipline as presented in the following subsections is an extension of Curry's system for the pure Lambda Calculus that does not have these drawbacks. It has developed over a period of several years; in the sequel, not just the ®nal version will be presented, but various systems that appeared between 1980 and 1992 will be shown, in order to develop a concise overview of the ®eld.

1.1 The Coppo-Dezani type assignment system

The ®rst paper by M. Coppo and M. Dezani-Ciancaglini from the University of Turin, Italy that introduced intersection types is [7] (in this paper, instead of the word `intersection', the word `sequence' was used). The system presented in this paper is a true extension of Curry's system:

the extension made is to allow of more than one type for term-variables in the ( I)-derivation rule

and therefore to allow of, also, more than one type for the right hand term in the ( E)-derivation rule.

De®nition 1.1.1 i) The set of types considered in [7] is inductively de®ned by:

a) All type-variables 0, 1, are types.

n n

b) If 1 n are types ( 1), then 1 is a sequence.

n c) If 1 n is a sequence and is a type, then 1 is a type.

ii) Type assignment and derivations are de®ned by the following natural deduction system.

x [ : 1 n ]

:

M

M

M

: 1 : n :

(I): ( I): (a)

M

xM n : 1 : 1 n

5

x

M N

: n n

1 : 1 n : 1

(E): ( E):

x

i

: MN :

x x M (a) If : 1 n is the only statement about on which : depends.

The main properties of that system proved in [7] are:

B M M N B N

Subject reduction: If : and , then : .

B M M Normalizability of typeable terms: If : , then has a normal form.

Typeability of all terms in normal form.

B M M B N N

Closure for -equality in the I-calculus: if : and = , then : .

B M M

In the I-calculus: : if and only if has a normal form.

M M It is even possible to prove that, in this system: If B : , then is strongly normalizable

(in fact, this follows from a similar result of [1]; there the BCD-system without is studied, which is a supersystem of the CD-system).

That the system is closed under subject reduction can be illustrated by the following `Cut and

B xM N

Paste' proof: Suppose that ( ) : . By( E), there is a sequence 1 n such that

B xM B N n

: 1 n and : 1 . Since (I) should be the last step performed for the ®rst result and ( I) should be the last step for

the latter, also

B x M B N i n n

: 1 : and : i , for1 .

M N x i n

Then a derivation for B [ ]: can be obtained by replacing, for every 1 , in the

B x M fx g x

n n

derivation for : 1 : , the sub-derivation : 1 : i by the derivation

B N

for : i .

The problem to solve in a proof for closure under -equality is then that of -expansion:

M N x B xM N

if B [ ]: , then ( ) : .

x M N

When restricting to I-terms, the term-variable occurs in and the term is a subterm of

N x N B M N x

M [ ], so is typed in the derivation for [ ]: , probably with several different types

1 n . In the CD-system a derivation for

B x M

: 1 n :

B M N x N

can be obtained by replacing in the derivation for [ ]: , all occurrences of : i by the

fx g x n derivation for : 1 : i . Then, obviously, using ( I), ( I), and ( E), the redex can

be typed.

x

The system is not closed for -expansion for the full K-calculus: when the term-variable

N M N x

does not occur in M , the term is a not a subterm of [ ], and if there is no such that

N

B : , the redex cannot be typed.

z z z z z z y y

Take, for example, the two lambda terms (( xy y )(( )( )))and ( ) (notice that the

y y

®rst term reduces to the second). Then of course : , but it is impossible to type the

z z z z z z

term (( xy y )(( )( ))). This can be understood from the fact that all typeable terms are z z z normalizable; the subterm (( z z z )( )) has no normal form, so is not typeable.

6

For a more intricate example that remains within the set of typeable terms, take the two lambda

bz y z y z z terms ( y z ( )( ))and ( ) (again the ®rst term reduces to the second). It is easy to show

that

z y g z

f : : : ,

y z

but it is impossible to give a derivation for ( bz )( ): from the same basis. This is caused by the

y z y fact that ((bz )( )) can only be typed in this system from a basis in which the predicate for is

an arrow type scheme. It is for example possible to derive

z y g bz y z f : : ( )( ): .

Therefore, it is possible to derive

y z bz y z y z z

( )( ):( ) and : ,

bz y z but not to give a derivation for y z ( )( ): . From this initial system several others emerged. The best known and most frequently quoted is the one presented in [6], but there are two earlier papers ([10] and [9]) that investigate interesting systems which can be regarded as in-between those of in [7] and [6]. In fact, the system that will be presented in Section 2 is more close to the system of [10] that to that of [6].

1.2 The Coppo-Dezani-Venneri type assignment systems

In [10] two type assignment systems are presented, that, in approach, are more general than the Coppo-Dezani system: in addition to the type constructors ` 'and` ', they also contain the type

constant ` '. The ®rst type discipline as presented in [10] (a similar system was presented in [35]) is a true extension of the one presented in [7]; the second one limits the use of intersection types

in bases. By introducing the type constant next to the intersection types, a system is obtained

N M M N

that is closed under -equality for the full K-calculus: if = , where and are lambda

M B N terms, then B : : .

De®nition 1.2.1 i) The set of types is inductively de®ned in [10] by:

a) All type-variables 0, 1, are types.

b) is a type.

n n

c) If 1 n are types, ( 1), then 1 is a sequence.

n

d) If 1 n is a sequence and is a type, then 1 is a type.

n

ii) Every type can be written as 1 n , where 1 are sequences, and is a

type-variable or . The type is called tail-proper if = .

iii) Type assignment and derivations are in [10] de®ned by:

x x n

[ : i ] [ : ]

M

M : : 1 : n

(I):

M :

M

: n

(I): (a) 1

xM :

7

M N n

: 1 n : 1

( ): ( E):

MN

M : :

x x x M

(a) If : 1, , : n are all and nothing but the statements about on which : depends,

and is a sequence that at least contains all 1 n .

Notice that is treated as a true type constant; the view of the strict intersection system presented in [1] (see Subsection 1.4) and that of the essential system presented in this paper (see Section 2)

is to treat as the empty intersection. The changes with respect to the system of [7] are small, but important. First of all, the type

constant , assignable to all terms, is introduced, which makes all terms having a head normal

form typeable; the type is needed to cover the subterms that have no normal form. Also, the (E) rule of [7] is implicitly present in ( I).

The main properties of this system proved in [10] are:

B M M N B N

If : and = , then : .

B M M

: and is tail-proper, if and only if has a head normal form.

B M B M : and does not occur in and , if and only if has a normal form.

That the system is now also closed for -expansion, is solved by the introduction of the type

constant and the sequences. The type constant is the universal type, i.e. each term can be

B M N x B xM N N

typed by . It can be used in the expansion from [ ]: to ( ) : to type

M N x B N N

if N does not occur in [ ], and there is no other type such that : . If does not

N x x M B xM N

occur in M [ ], does not occur in , and there is a derivation for : . Since

B xM N is typeable by , by derivation rule ( E) also ( ) : .

The sequences allow, as in the CD-system, for a term-variable to have different types within

M N x

a derivation; they are used for the cases that N occurs more than once in [ ], and these

M N x occurrences were typed in the derivation for B [ ]: with different types. (See also Lemma 2.9.)

De®nition 1.2.2 i) The set of normalized types is inductively de®ned in [10] by:

a) All type-variables 0, 1, are normalized types.

b) is a normalized sequence.

n i n

n n c) If 1 are normalized types ( 1) and, for 1 , i = , then 1 is a

normalized sequence.

d) If 1 n is a normalized sequence and is a normalized type, where = , then

1 n is a normalized type.

ii) On the set of types, the relation is de®ned by:

a) .

n i

b) i

n i

1 +1 1 i+1

i n

1 [ i ].

i

c) & .

8 Observe that the only normalized non-tail-proper type is .

A good justi®cation for identi®cation of types through can be found in the de®nition of type-semantics (De®nition 1.3.5). Notice that, in fact, normalizing types as done here is just the

same as treating as an empty intersection; the set of normalized types coincides with the set of strict types (see De®nition 1.4.1), and normalized sequences correspond to strict intersection types. The second type assignment system presented in [10] is a restricted version of the ®rst. Since

it limits the possible bases that can be used in a derivation, it is not a proper extension of Curry's

M x B xM

system: if B : and the term-variable does not occur in , then for ( ) only the type

can be derived. This system is also used in [19].

De®nition 1.2.3 Restricted type assignment and restricted derivations are in [10] de®ned by:

x x

[ : 1] [ : n ]

M

M : : 1 : n

(I): (b)

M :

M

: n

(I): (a) 1

xM

: 1 n

M N n

: 1 n : 1

( ): ( E):

MN

M : :

x x x M

(a) If = and : 1, , : n are all and nothing but the statements about on which :

M x

depends. If n = 0, so in the derivation for : there is no premise whose subject is , then

1 n = .

i n

(b) If for 1 , i = .

This notion of type assignment is relevant in the sense of [15]: in the (I)-rule, only those

types actually used in the derivation can be abstracted. This implies that, for example, for the

lambda term ( aba) the type cannot be derived.

M B M It is obvious that B : in the restricted system implies : in the unrestricted one

and that the converse does not hold. In both systems, types are not invariant by -expansion, since

xx xy xy for example : , but not : . Moreover, type assignment in the unrestricted

system is not invariant under -reduction: for example

xy xy xx

:( ) , but not :( ) .

This is due to the fact that, in the unrestricted system, there is no way to obtain x: from

x: . In the restricted system, in the ( I)-rule, only types actually used for a term variable can

be collected. This means that the statement xy xy :( ) cannot be derived, since the xy type is not used for the application .

The closure under -reduction, however, holds for the restricted system; properties of this

restricted system proved in [10] are:

B M

If : , then is a normalized type.

B M M N B N

If : and , then : .

9 1.3 The Barendregt-Coppo-Dezani type assignment system

The type assignment system presented in [6] by H. Barendregt, M. Coppo and M. Dezani-

Ciancaglini is based on the ®rst, unrestricted system as presented in [10]. It extended the set

T

of types to , introduced a partial order relation ` ' on types, added the type assignment rule ( ),

and introduced a more general form of the rules concerning intersection. The rule ( ) was mainly introduced to prove completeness of type assignment. In this paper, it was shown that the set of types derivable for a lambda term in the extended

system is a ®lter, i.e. a set closed under intersection and right-closed for . The interpretation of

[[M ]]

a lambda term by the set of types derivable for it ± ± is de®ned in the standard way and

F

gives a ®lter -model . The main result of that paper is that, using this model, completeness

M M T F

[[ ]]

is proved by proving the statement: : ( ), where : is a simple

type interpretation as de®ned in [23] (see De®nition 1.3.5(ii)). In order to prove the ` '-part of

this statement (completeness), the relation is needed. Other interesting applications of ®lter

-models can be found in [8], [11], [16], and [17]. T

De®nition 1.3.1 i) , the set of types in [6] is inductively de®ned by:

T

a) All type-variables 0, 1, .

T

b) .

T T

c) If and , then and .

T

ii) On , the type inclusion relation is inductively de®ned by:

a) .

b) .

c) .

d) , .

e) ( ) ( ) .

f) .

g) & .

h) & .

iii) .

T

may be considered modulo . Then becomes a partial order.

Notice that, because of part (i.c),`' is now also a general type constructor. This is in harmony

with the fact that also is treated as a `normal' type constant, but is not motivated by the type

system itself. The decision to treat ` ' in this way stems from a, in the eyes of this author, wrong line of thought. In order to solve the problem of completeness of type assignment, ®rst the set of types is expanded, where the introduction of a relation on normalized types with contra-variance in the arrow would have done the trick. The goal of this paper is to show that, had the authors restricted themselves to the normalized types of [10] (De®nition 1.2.2) and introduced a relation

on those types (essentially composed of parts (ii.a), (ii.b), (ii.d), (ii.f), (ii.g), and (ii.h)), they would have obtained a system with the same expressiveness as that one they de®ned. This system would then have been identical to the essential system as presented in this paper (Section 2).

10 De®nition 1.3.2 i) Type assignment and derivations are in [6] de®ned by the following natural

deduction system. [x: ]

:

M N

: : M : (E):

( I): (a)

MN :

xM :

M M M

: : M : :

( E): (I):

M M

: : M :

M

:

( ): ():

M

: M :

x M

(a) If x: is the only statement about on which : depends.

B M M B

ii) : means that : is derivable from a basis using these rules.

An advantage of the presentation in [6] is, clearly, a very easy type de®nition and easy

understandable derivation rules. But this advantage is super®cial, since all dif®culties now show up while proving theorems; especially the complexity of and causes confusion.

For this notion of type assignment, the following properties hold:

B MN B M B N

Lemma 1.3.3 i) : [ : & : ].

B xM B x M

ii) : [ = & : : ].

B x x B

iii) : [ : & ].

In the BCD-system, there are several ways to deduce a desired result, due to the presence

of the derivation rules ( I), ( E) and ( ), which allow super¯uous steps in derivations. In the CDV-systems, these rules are not present and there is a one-one relationship between terms and skeletons of derivations. In other words: those systems are syntax directed. The BCD-system has

the same expressive power as the previous unrestricted CDV-system: all solvable terms have types other than , and a term has a normal form if and only if it has a type without -occurrences. The main result of [6] is the proof for completeness of type assignment. The construction of

a ®lter -model and the de®nition of a map from types to elements of this model (a simple type

interpretation) make that proof possible: if the interpretation of the term M is an element of the

M

interpretation of the type , then is typeable with .

F

Filters and the ®lter -model are de®ned by:

d T

De®nition 1.3.4 i) A ®lter is a subset such that:

d

a) .

d d

b) .

d d

c) .

F fd j d g

ii) = is a ®lter .

11

d d F d d f T j d d g iii) For 1 2 de®ne 1 2 = 2 [ 1] .

Notice that, because of part (i.a), a ®lter is never empty.

The following properties are proved in [6]:

M Λ f j B B M g F

[ [ : ]].

F B fx j x g M Λ

Let be a valuation of term-variables in and = : ( ) . For de®ne

f j B M g

[[M ]]

= : . Using the de®nition of Hindley and Longo [24] it is shown that

i hF [[ ]]

, , is a -model.

In constructing a complete system, the semantics of types plays a crucial role. As in [17], [29], and essentially following [22], a distinction can be made between several notions of type interpretations and semantic satis®ability. There are, roughly, three notions of type semantics that differ in the meaning of an arrow type scheme: inference type interpretations, simple type interpretations and F type interpretations. These different notions of type interpretations induce of

course different notions of semantic satis®ability.

hD i T D fX j

De®nition 1.3.5 i) Let be a continuous -model. A mapping : ( ) = D g

X is a type interpretation if and only if:

d j e d e g

a) f ( )[ ( )] ( ).

fd j e d e g

b) ( ) ( )[ ( )] .

c) ( ) = ( ) ( ).

ii) Following [23], a type interpretation is simple if also:

fd j e d e g ( ) = ( )[ ( )] .

iii) A type interpretation is called an F type interpretation if it satis®es:

f d j e d e g ( ) = ( )[ ( )] .

Notice that, in part (ii), the containment relation of part (i.b) is replaced by =, and that in part (iii) the same is done with regard to part (i.a). These notions of type interpretation lead, naturally, to the following de®nitions for semantic

satis®ability (called inference-, simple- and F-semantics, respectively).

hD i D

De®nition 1.3.6 i) Let M = [[ ]] be a -model and a valuation of term-variables in .

M

D M M

Then [[M ]] is the interpretation of in via .

M

ii) De®ne by (where is a -model, a valuation and a type interpretation):

M

M M M

a) : [[ ]] ( ).

x B M M x B

b) : for every : .

M M B M B M M

c) 1) : [ : ].

B M M

2) s : , simple type interpretations

M B M M

[ : ].

B M M

3) F : F type interpretations

M B M M [ : ].

12 Since no confusion is possible, the superscript on [[ ]] is omitted.

The main result of [6] is obtained by proving:

B M B M

Property 1.3.7 i) Soundness. : s : .

B M B M ii) Completeness. s : : .

The proof of completeness is obtained in a way very similar to that of Theorem 4.3.6. The results of [6] in fact show that type assignment in the BCD-system is complete with respect to simple type semantics; this in contrast to strict type assignment (presented in [1], see also the next subsection), that is complete with respect to the inference semantics.

1.4 The strict type assignment system

The strict type assignment system as de®ned in [1] is a restriction of the system of [6]; it is a type assignment system in which the relation and the derivation rule ( ) are no longer present. The

elimination of induces a set of strict types, that is actually the set of normalized tail-proper types

of [10]. Moreover, there the relation S on strict types is presented, that is more restricted than

just the relation restricted to strict types. Instead, it is the relation generated by interpreting

the type-constructor as intersection on sets; in particular, S is not de®ned over ` '-types, so part (ii.h) of De®nition 1.3.1 is missing. The derivation rules used are similar to those of the unrestricted system in [10]. This implies that, formally, the strict system is a system in between the two presented in [10]; a signi®cant difference with the restricted system of [10] is that type assignment in the strict system is not relevant in the sense of [15]. Although the rather strong restrictions imposed, the provable results for the strict system are very close to those for the system of [6]. For example, the sets of normalizable terms and those having a normal form can be equally elegantly characterized. The main difference between the

two systems is that the strict system is not closed for -reduction, whereas the BCD-system is. F

The strict system gives rise to a strict ®lter -model S, that satis®es all major properties of

F

the ®lter -model as presented in [6], but is an essentially different -model, equivalent to

D Engeler's model A [18]. In [1] was shown that soundness for the notion of type assignment of [6]

is lost if instead of simple type semantics, the inference type semantics is used. Take, for example,

xx

the statement :( ) ( ) : this statement is derivable in the system , but it is not

valid in FS. With the use of the inference type semantics, in [1] soundness and completeness for

strict type assignment was proved, without having the necessity of introducing ; this was done

using FS.

The set of types assignable to a term M in the strict system is signi®cantly smaller than the

set of types assignable to M in the BCD-system. In particular, the problem of type checking for the strict system is, because of the smaller equivalence classes, less complicated than for the BCD-system. Strict types are the types that are strictly needed to assign a type to a term in the BCD-system.

In the set of strict types, intersection type schemes and the type constant play a limited role.

Perhaps the most important change from the systems presented before is that the type constant

is no longer treated as an arbitrary type, that can be handled in any way. Instead, is taken to

n be the empty intersection: if = 0, then 1 n , so does not occur in an intersection

13 subtype. Moreover, intersection type schemes (so also ) occur in strict types only as subtypes at

the left-hand side of an arrow type scheme, as in the types of [7], [9], and [10]. T De®nition 1.4.1 i) Ts, the set of strict types, and S, the set of strict intersection types, are de®ned

by mutual induction by:

T T T T

a) All type-variables 0, 1, s, and if s and S, then s.

T n T n

b) If 1 n s ( 0), then 1 S.

ii) On TS, the relation S is de®ned by:

i n n n

a) 1 ( 1) [ 1 S i ].

i n n n

b) 1 ( 0) [ S i ] S 1 .

c) S S S .

iii) On TS, the relation S is de®ned by:

a) S S S .

b) S & S S . T

Notice that Ts is a proper subset of S, and that the second part of (i.a) can also be formulated as:

T n T n

If 1 n s ( 0), then 1 s. Moreover, S if and only if can be

obtained from by premuting components of an intersection subtype, e.g. in S .

The de®nition of S as in [1] did not contain part 1.4.1 (iii.b), but was de®ned by: S

S S . As was remarked by Professor G. Plotkin of the University of Edinburgh,

Scotland (private communication), de®ning the equivalence relation on types in that way causes

an anomaly in the de®nition of type-interpretation. In particular, the types and

would be incomparable, which implies that the interpretation of an arrow type is no longer a map from the interpretation of onto the interpretation of .

De®nition 1.4.2 i) Strict type assignment and strict derivations are de®ned by the following nat-

ural deduction system (where all types displayed are strict, except for in the rule ( I)):

M N N n

: 1 n : 1 :

n

(E): ( 0)

MN : [x: ]

:

x

: 1 n M :

(E): (b)

( I): (a) x

: i

xM :

x M

(a) If x: is the only statement about on which : depends.

i n

(b) n 2 1 .

M M B

ii) B s : is used for: : is derivable from using a strict derivation, and S is de®ned

B M n n

by: S : if and only if: there are 1 n ( 0) such that 1 , and for

i n B M

every 1 , s : i .

14

Notice that the derivation rule ( E) is only performed on variables and that the derivation rules

( ) and ( I) of the BCD-system are implicitly present in the derivation rule ( E). Moreover, a

M

derivation in the S system with conclusion : cannot be composed with any other derivation.

The derivation rule ( E) could be replaced by a rule for ( S), in the spirit of the rule ( ) of the BCD-system, but allowed only for term-variables. Also, the derivation rules ( I) and ( E)

together correspond to the derivation rule ( I) of the unrestricted CDV-system (De®nition 1.2.1).

F F The strict ®lter -model S is de®ned in a way very similar to de®ned in [6], by de®ning

®lters of types and a map from terms to ®lters. T

De®nition 1.4.3 i) A subset d of S is called a strict ®lter if and only if:

d n d n

a) 1 n ( 0) 1 .

d d

b) & S .

T V V f g

ii) If V S, then S is the smallest strict ®lter that contains , and S = S .

fd T j d g F

iii) FS = S is a strict ®lter . Application on S is de®ned by:

e f j e d g

d = S [ ] .

d

Notice that if types are not considered modulo S then part (i.b) should also contain: & S

d

. Notice also that every strict ®lter contains .

F F

The ®lter -models S and are not isomorphic as complete lattices, since, for example,

F F

in the ®lter ( ) is contained in , but in S the strict ®lter S( ) is not

F

contained in S . Moreover, they are not isomorphic as -models since in the meaning of

xx F

(xy xy ) is contained in the meaning of ( ), while this does not hold in S. Another difference F

is that, while the analogue of G in chooses the minimal representative of functions, this is not F

the case in FS. Moreover, it is straightforward to show that S is equivalent to Engeler's model D

A . The main results of [1] are:

Soundness and completeness of type assignment with respect to inference type semantics.

B M B T B M B B

If : then there are S such that S : , and .

B T B M B M

Conservativity. Let S. If : , then S : .

B M B M

In the BCD-system without , restricted to the I-calculus: s : : .

fM j M

In the BCD-system without : is typeable by means of the derivation rules ( I), ( E),

g fM j M g (I) and ( E) = is strongly normalizable .

2 The essential intersection type assignment system

In this section the essential type assignment system is presented, a restricted version of the system presented in [6], together with some of its properties. The major feature of this restricted system is, compared to the BCD-system, a restricted version of the derivation rules and the use of strict types. It also forms a slight extension of the strict type assignment system that was presented in

[1] (see Subsection 1.4); the main difference is that the strict system is not closed for -reduction,

whereas the essential system presented here is. T Recall De®nition 1.4.1. The relation E on S, to be de®ned below, is a natural extension of

15 the relation S, that was only de®ned for intersection types. Notice that, in the de®nition of E,

the arrow type constructor is contra-variant in its left-hand argument.

T

De®nition 2.1 i) The relation E is de®ned on S like S, by adding the last alternative.

i n n n

a) 1 ( 1) [ 1 E i ].

i n n n

b) 1 ( 0) [ E i ] E 1 .

c) E E E .

d) E & E E .

ii) On TS, the relation E is de®ned by: E E E .

B x B x B B B

iii) B E if and only if for every : there is an : such that E , and E

B B

B E E .

Also the relations , , and S are extended to bases.

T

Notice that E is exactly the relation restricted to S (see also Property 4.1.2), soif E ,

then , and that S is a true subrelation of E, since, for example, ( ) ( ) E ,

T but this does not hold in S. Moreover, S may be considered modulo E; then E becomes a

partial order, and from now on in this paper types are considered modulo E.

n Unless stated otherwise, if a type is written as 1 n , then all 1 are assumed to

be strict. Remember that is de®ned to be the emtpy intersection.

B B ΠfB B g n

De®nition 2.2 If 1 n are bases, then 1 is the basis de®ned as follows:

x ΠfB B g fx x g x

n m

: 1 m 1 if and only if : 1 : is the set of all statements about

B B

that occur in 1 n .

fx g B x ΠfB fx gg x Often B : (or : ) will be written for the basis : , when does not occur in

B .

For the relation E, the following properties hold:

Lemma 2.3 i) S E .

f j g fg

ii) E . So E = .

f j g f g

iii) E . So E = .

T T T

iv) E s S, s [ & E & E ].

T i n n

v) 1 E s 1 [ i E ].

j m i n

m n m

vi) E 1 n 1 [ = 1 & = 1 & 1 1

j [ i E ]].

Proof: Easy.

The essential type assignment system is constructed from the set of strict types and an extension of the derivation rules as in De®nition 1.4.2. In this way, a syntax directed system is obtained, that satis®es the main properties of the BCD-system.

16

De®nition 2.4 i) Essential type assignment and essential derivations are de®ned by the following natural deduction system (where all types displayed are strict, except in the rules ( I) and

(E)):

M N N n

: 1 n : 1 :

n

(E): ( 0)

MN : [x: ]

:

x

: E

M : (E):

(I): (a)

x:

xM :

x M

(a) If x: is the only statement about on which : depends.

M M B

B e : is de®ned as: : is derivable from using an essential derivation.

B M n n

ii) De®ne E by: E : if and only if: there are 1 n ( 0) such that 1

B M i n

and e : i , for every 1 .

Notice that the difference between the strict system and the essential one lies only in the derivation rule for term variables. Instead of a rule ( E), that is in fact de®ned using the relation S, the

essential system contains a similar rule using E.

The introduction of two different notions of derivability seems somewhat super¯uous. In fact, the `real' notion of type assignment is that de®ned as e ; the symbol E is mainly introduced for convenience, as an abbreviation.

For these notions of type assignment, the following properties hold:

x T x B

Lemma 2.5 i) B E : S [ : & E ].

MN T B M B N

ii) B e : S [ e : & E : ].

xM T T B x M

iii) B e : S, s [ = & : e : ].

M B M T

iv) B e : E : & s.

B M i n B M

n n

v) E : 1 [ = 1 & 1 [ e : i ]].

M fx B j x M g M

vi) B E : : FV( ) E : .

M B B B M

vii) B E : & E E : .

<

B M M M B

viii) E : & M E : . 

Proof: Easy.

Although the rule ( E) is de®ned only for term-variables, E is closed for E.

M B M

Lemma 2.6 If B E : and E , then E : , so the following is an admissible rule in E:

M : E

(E): M :

Proof: By induction on E.

17

B M

i) = . Then, by Lemma 2.3 (iii), = . Obviously, E : .

i n B M n

ii) = 1 . By Lemma 2.5(v), for every 1 , e : i . By Lemma 2.3(vi), there

T j m i n m

are 1 m s such that = 1 and, for every 1 , there is a 1 such

j m B M

j j

that i E . By induction, for every 1 , e : . But then, by Lemma 2.5(v),

M

B E : .

T M

iii) s. This part is proven by induction on .

x B fx g fx g B x

a) M . Then E : E : , so, by Lemma 2.5(i), E : .

xM T T

b) M . Then, by Lemma 2.5 (iii), there are S, s such that = and

B x M n

: e : . By Lemmas 2.3(vi) and 2.3(iv) there are 1 n 1 such that

i n

n n i

=( 1 1) ( ), and for 1 , i E and E . By Lemma 2.5 (vii), for

i n B x M B x M

i i

1 , : i e : , and by induction : e : . So, by Lemma 2.5 (iii), for

i n B xM B xM i

every 1 , e : i , so, to conclude, by Lemma 2.5(v), E : .

M M T B M

c) M 1 2. Then, by Lemma 2.5(ii), there is a S such that e 1: and

M B M

B E 2: . Since E , also E and, by induction, e 1: . Then, by

M M Lemma 2.5(ii), B E 1 2: .

Now it is easy to prove that type assignment in this system is closed under -reduction. The proof for this result is split in two parts, Lemma 2.7 and Theorem 2.8. The lemma is also used in

the proof of Lemmas 3.2.1, Theorem 3.2.5, and Theorem 6.2.15.

M x x M B M

Lemma 2.7 B x: e : & FV( ) e : .

M x x M

Proof: B x: e : & FV( ) (2.5(ii))

B x M B x x x M

[ : e : & : E : ] (2.5(i), not in )

B M

[ e : & E ] (2.1)

B M

[ e : & E ] (2.6)

M

B e : .

B M M N B N

Theorem 2.8 If E : and , then E : . T

Proof: Only the part s is shown. The proof is completed by induction on the de®nition of

xM x M x M

, of which only the part is shown, where does not occur free in . The other

xM x

parts are dealt with by straightforward induction. Then: B e : (2.5 (iii))

B x M x B M

[ = & : e : ] (2.7) e : .

xy xy xx For example, E :( ) and E :( ) are both easy to

derive. As in [9,6,1], it is possible to prove that the essential type assignment system is closed under = . In the ®rst paper, this result was obtained by a `Cut and Paste'-proof (see Subsection 1.1). In the

latter two papers this result was obtained by building a ®lter -model as sketched in Section 1.3;

from the fact that every M is interpreted by the set of its assignable types, and that set is a ®lter, the result is then immediate (see also Corollary 4.3.5). In this paper the result will ®rst be

obtained directly, without constructing a ®lter model; in this way the precise behaviour of the type constructor ` ' and the type constant can be made apparent. First, a substitution lemma is proved. Notice that, unlike for many other notions of type

18 assignment (Curry's system, the CD-system, the polymorphic type discipline [20]), the implication

holds in both directions.

B x M B N B M N x

Lemma 2.9 [ : E : & E : ] E [ ]: .

T Proof: By induction on M . Only the case s is considered, of which only the non-trivial parts

are shown.

x

i) M .

B x x B N

) [ : e : & E : ] (2.5(i))

B N

[ E & E : ] (2.5(iv) & 2.6)

x N x

B e [ ]: .

y x

ii) M = .

B y N x B y B N

) e [ ]: e : & E : .

y M

iii) M . By Lemma 2.5 (iii) and induction.

M M

iv) M 1 2.

B M M N x

) e 1 2[ ]: (2.5(ii) & IH)

B x M B N

1 2 [ : i e 1: & E : 1 &

M B N

B x: 2 E 2: & E : 2] ( = 1 2 & 2.5(v) & 2.5 (vii))

B x M M B N

[ : e 1 2: & E : ].

M B M B N Theorem 2.10 = N ( : : ), so the following rule is an admissible rule E E

in E:

M N

M

: =

(= ):

N :

Proof: By induction on the de®nition of = . The only part that needs attention is that of a redex,

xM N B M N x T

B E ( ) : E [ ]: , where s; all other cases follow by straightforward

xM N

induction. To conclude, notice that, if B E ( ) : , then, by Lemma 2.5(ii) & (iii),

M B N [B x: E : & E : ]. The result follows then by applying Lemma 2.9.

3 Approximation and normalization results

In [34] an approximation theorem is proved, that formulates the relation between the types assignable to a term and those assignable to its approximants, as de®ned in [37] (see De®ni-

tion 3.1.1 below).

B M A A M B A

Property 3.1 : if and only if there exists ( ) such that : .

In this section, an `essential' variant of this property will be proved; for every M B and

M A A M B A

such that B E : , there is an ( ) such that E : . In [34] this result is obtained

through a normalization of derivations, where all ( I)±( E) pairs, that derive a type for a redex

N M N x (xM ) , are replaced by one for its reduct [ ], and all pairs of ( I)±( E) are eliminated. (This technique is also used in [9] and [6]. It requires a rather dif®cult notion of length of a

19 derivation to show that this process terminates.) In this paper, this result will be proved using the computability technique, following Tait [36], as was done in [11], and [17]. With this result, it can be shown that the BCD-system is conservative over the essential system

(Theorem 4.1.5), and prove that the set of all terms having a (head) normal form are typeable in e (with a type without -occurrences) (Theorem 3.3.2).

3.1 Approximate normal forms

The notion of approximant was ®rst presented by C. Wadsworth [37] and is de®ned using the

<

notion of terms in -normal form (like in [5], is used, instead of ; also, the symbol is used 

as a relation on Λ-terms, inspired by a similar relation de®ned on BÈohm-trees in [5]).

Λ Λ De®nition 3.1.1 i) The set of -terms is de®ned as the set of lambda terms, extended by:

Λ.

ii) The notion of reduction is de®ned as , extended by:

a) x. .

M

b) .

Λ N

iii) The set of normal forms for elements of with respect to is the set of -normal

forms or approximate normal forms and is inductively de®ned by:

a) N .

N A xA N

b) If A , = , then .

A A N n xA A N n c) If 1, , n ( 0), then 1 .

The rules of the essential system are generalized to terms containing by allowing for the terms to Λ

be elements of . This implies that, because essential type assignment is almost syntax directed,

M B M M

if occurs in a term and E : , then either = , or in the derivation for : , appears n

in the right hand subterm of an application on which the rule ( E) is used with = 0. Moreover,

x M M the terms . and 1 n are typeable by only.

2

< Λ

De®nition 3.1.2 i) The relation ( ) is de®ned by:



< M

a) .



< x

b) x.



< <

M xM xM

c) M .

 

< < <

M M M M M M M

d) M1 & 2 1 2 .

 

 1 2 1 2

<

A N M Λ A A M

For , , if M , then is a direct approximant of .



<

N Λ A v M M M A M

ii) The relation is de®ned by: = [ ].



M A M

If A , then is an approximant of .

M fA N j A v M g iii) A( ) = .

The following properties of approximants hold:

20

A A xM M A A N

Lemma 3.1.3 i) If ( 1 n ) and ( ), then

AA A xM M N

( 1 n ).

A M z z M

ii) If A ( ) and FV( ), then either:

A z z A A A M

a) A , FV( ), and ( ), or

A M b) z A ( ). Proof: Easy.

3.2 Approximation result

In this subsection, the approximation theorem will be proved. For reasons of readability, in this

A A M B A App B M

subsection ( )[ E : ] will be abbreviated by ( ).

App B xM M App B N

Lemma 3.2.1 i) ( 1 n ) & ( )

App ΠfB B g xM M N

( 1 n ).

pp B fz g M z z M T App B M

ii) A ( : ) & FV( ) & s ( ).

pp B M N x App B xM N

iii) A ( C[ [ ]] ) ( C[( ) ] ).

A A xM M B A A A N B A Proof: i) ( 1 n ) & E : & ( ) & E :

(3.1.3(i) & 2.5(ii))

AA A xM M N ΠfB B g AA

( 1 n ) & E : .

A M z B z A z M

ii) A ( ) & : E : & FV( ) (3.1.3(ii))

A z z A A A M B z A z

a) A & FV( ) & ( ) & : e : (2.7)

A M B A

A ( ) & e : .

A M B z A z A A M B z A

b) z A ( ) & : e : ( ) & e : .

M A M A M

iii) Since = M implies ( ) = ( ).

In order to prove that for each term typeable in E an approximant with the same type can be found, a notion of computability is introduced.

De®nition 3.2.2 Comp (B M ) is inductively de®ned by:

B M App B M

i) Comp (B M ) E : & ( ).

B N ΠfB B g M N

ii) Comp (B M ) ( Comp ( ) Comp ( )).

B M i n B M n iii) Comp ( 1 ) 1 [Comp ( i )].

Notice that Comp (B M ) holds as special case of part (iii).

B M B M Lemma 3.2.3 Take and such that E . Then Comp ( ) Comp ( ).

Proof: By straightforward induction on the de®nition of E.

M N x B xM N Lemma 3.2.4 Comp (B C[ [ ]] ) Comp ( C[( ) ] ).

Proof: By induction on the structure of types. The case that is a type-variable follows from Theorem 2.10 and Lemma 3.2.1 (iii).

21

B xM M App B xM M n

Theorem 3.2.5 i) E 1 n : & ( 1 )

B xM M

Comp ( 1 n ).

B M App B M ii) Comp (B M ) E : & ( ).

Proof: Simultaneously by induction on the structure of types. The only interesting case is when

= ; the other cases are dealt with by induction.

B xM M App B xM M n

i) E 1 n : & ( 1 ) (IH(ii))

B N B xM M B N

( Comp ( ) E 1 n : & E : &

App B xM M App B N

( 1 n ) & ( )) (2.5(ii) & 3.2.1(i))

B N ΠfB B g xM M N

( Comp ( ) E 1 n : &

App ΠfB B g xM M N

( 1 n )) (IH(i))

B N ΠfB B g xM M N

( Comp ( ) Comp ( 1 n )) (3.2.2(ii))

B xM M

Comp ( 1 n ).

z M

ii) Comp (B M ) & FV( ) (IH(i))

fz g z z M

Comp (B M ) & Comp ( : ) & FV( ) (3.2.2(ii))

fz g M z z M

Comp (B : ) & FV( ) (IH(ii))

fz g M z App B fz g M z z M

B : E : & ( : ) & FV( ) (2.7 & 3.2.1(ii))

M App B M

B E : & ( ).

x g x x

Notice that, by part (ii), in particular Comp (f : ), for all .

B fx x g B M i n B N

n n

i i

Theorem 3.2.6 If = 1: 1 : , E : , and, for every 1 , Comp ( i ),

B B g M N x N x Πf

n n

then Comp ( 1 n [ 1 1 ] ). T Proof: By induction on the structure of types, of which only the part s is presented. This is

shown by induction on the structure of derivations.

M y M B y M

(I): Then , = , and : E : .

B fx x g i n B N

n n

i i

= 1: 1 : & 1 [Comp ( i )] &

M

B y : E : (IH)

N

(Comp (B )

ΠfB B B g M N x N x N y

n n

Comp ( 1 n [ 1 1 ] )) (3.2.4)

N

(Comp (B )

ΠfB B B g y M N x N x N

n n

Comp ( 1 n ( [ 1 1 ]) )) (3.2.2(ii))

B B g y M N x N x Πf

n n

Comp ( 1 n ( )[ 1 1 ] ).

M M M B M B M

(E): Then 1 2, E 1: , and E 2: .

B fx x g i n B N

n n

i i

= 1: 1 : & 1 [Comp ( i )] &

M B M B E 1: & E 2: (IH)

Π fB B g M N x N x

n n

Comp ( 1 n 1[ 1 1 ] ) &

B B g M N x N x Πf

n n

Comp ( 1 n 2[ 1 1 ] ) (3.2.2(ii))

B B g M M N x N x Πf

n n Comp ( 1 n ( 1 2)[ 1 1 ] ).

(E): By Lemma 3.2.3.

As for the BCD-system and the strict system, the relation between types assignable to a lambda term and those assignable to its approximants can be formulated as follows:

22

M A A M B A

Theorem 3.2.7 B E : ( )[ E : ].

B M B M A A M B A

Proof: ) E : (3.2.6) Comp ( ) (3.2.5(ii)) ( )[ E : ].

B A

) If E : , then by the remark made after De®nition 3.1.1, appears only in subterms that

<

M M M M A M

are typed by . Since A A( ), there is an such that = and . Then, by



M B M Lemma 2.5 (viii), B E : and, by Theorem 2.10, also E : .

3.3 Normalization results

To prepare the characterization of terms by their assignable types, ®rst is proved that a term in

-normal form is typeable without , if and only if it does not contain . This forms the basis

for the result that all normalizable terms are typeable without .

A B A

Lemma 3.3.1 i) If B E : and are -free, then is -free.

B B A ii) If A is -free, then there are -free and , such that e : .

Proof: By induction on A.

T A xA A

i) As before, only the part s is shown; only the part 1 n is of interest. Then, by

x B

n n

Lemma 2.5(ii) and (i), there are 1 n 1 , such that : 1 , for

i n B A

n n i

every 1 , E i : , and 1 E 1 . So, especially, for every

i n i n B A

i i i i

1 , i E . By Theorem 2.8, also for every 1 , E : . Since each occurs

B A xA A n

in , all are -free, so by induction each i is -free. Then also 1 is -free.

xA B B A B x

ii) a) A . By induction there are such that e : and are -free. If does

T x B

not occur in B , take an -free s. Otherwise, there exist : , and is -free. In any

nx xA B n x

case, B E : , and and are -free.

A xA A n B B

n n

b) 1 n , with ( 0). By induction there are 1 and 1 such that

i n B A B

i i i i

for every 1 , i e : , and are -free. Take strict, such that does not

B ΠfB B fx gg B xA A B

n n

occur in , and = 1 n : 1 . Then E 1 : , and and , are -free.

Now, as in [1] for the strict system, it is possible to prove that the essential type assignment

system satis®es the main properties of the BCD-system.

B B M B M

Theorem 3.3.2 i) [ e : & -free] has a normal form.

B B M M

ii) [ e : ] has a head normal form.

B M A A M B A

Proof: i) ) If e : , then, by Theorem 3.2.7, ( ) [ E : ]. Because of

M M

Lemma 3.3.1(i), this A is -free. By De®nition 3.1.1, there exists = such that

<

A A A M M M

M . Since is -free, in fact , so itself is in normal form, so, especially, 

has a normal form.

M M

) If is the normal form of , then it is a -free approximate normal form. Then,

B B M

by Lemma 3.3.1(ii), there are -free such that e : . Then, by Theorem 2.10,

M

B e : .

B M A A M B A

ii) ) If e : , then, by Theorem 3.2.7, ( )[ E : ]. By De®nition 3.1.1, there

<

M M A M T A A xA xA A n

exists = such that . Since s, , so is either 1 or 1 , 

23

n A v M M xM xM M M with 0. Since , is either 1, or 1 n . Then has a head-normal

form.

M M M M x xM

) If has a head-normal form, then there exists = such that is either , 1

xM M M Λ n

or 1 , with each i .

xM M B T

1) M 1. Since 1 is in head-normal form, by induction there are s such that

M x B B n x xM B xM

B E 1: . If : , then e 1: , otherwise e 1: .

M xM M n T 2) 1 n ,( 0). Take s, then

Π fB B fx gg xM M n

1 n : e 1 : .

B B M B M

Corollary 3.3.3 i) [ E : & -free] has a normal form.

B B M M ii) [ E : & = ] has a head normal form.

4 Soundness and completeness of essential type assignment

4.1 The relation between the BCD- and the essential system

The essential system is the nucleus of the BCD-system: in this subsection it will be shown that, for any derivation in the BCD-system, it is possible to ®nd an equivalent derivation in the essential

system.

T T The proof is based on the fact that for every there is a S such that , and the

Approximation Theorem 3.2.7.

T T

De®nition 4.1.1 (cf. [22,1]) i) For every , S is inductively de®ned as follows:

a) = .

n T

n n

b) ( ) = ( 1) ( ), if = 1 ( 0), each i s.

f g f f g j g

n m n

c) ( ) = , where = i = . m

1 1 1 1 i

fx j x B g

ii) B = : : .

T T T

Since S is a proper subset of , is also de®ned for S. Notice that = , as a special

case of part (i.c), and that ( ) = , as a special case of part (i.b).

T

Lemma 4.1.2 i) [22,1] For every , .

T T

ii) modulo is isomorphic to S modulo E .

iii) E .

T iv) S = . Proof: Easy.

The proof for the main theorem of this section is achieved by proving ®rst, that for every term

N

in , typeable in , a derivation in the essential system can be built for which basis and type in

the conclusion are equivalent, and afterwards generalizing this result to arbitrary lambda terms.

B A B A Theorem 4.1.3 : E : .

24 Proof: By induction on the structure of terms in N , using Lemmas 1.3.3, 2.5, and 4.1.2 (iii).

The relation between the two different notions of type assignment is formulated as follows:

B M B M

Theorem 4.1.4 : E : .

B M A A M B A

Proof: : (3.1) ( )[ : ] (4.1.3)

A A M B A B M ( )[ E : ] (3.2.7) E : .

The BCD system is a conservative extension of the essential system.

B T B M B M

Theorem 4.1.5 Conservativity. Let S. If : , then E : .

B M B M B M Proof: : (4.1.4) E : (4.1.2(iv)) E : .

Obviously, since the essential system is a subsystem of the BCD-system, the implication in the

B M B M other direction also holds: If E : , then : . Also using this last result, it is possible to prove completeness of essential type assignment with respect to the simple type semantics (see Theorem 4.3.7).

4.2 An essential ®lter -model

As in [6] and [1], a ®lter -model can be constructed. Names will be used to distinguish between

the de®nition of ®lters in those papers and the one given here. T

De®nition 4.2.1 i) A subset d of S is an essential ®lter if and only if:

d n d n

a) 1 n ( 0) 1 .

d d

b) & E .

T V V

ii) If V is a subset of S, then E is the smallest essential ®lter that contains , and E =

f g

E .

fd T j d g F

iii) FE = S is an essential ®lter . Application on E is de®ned by:

e f j e d g d = E [ ] .

Notice that every strict ®lter (De®nition 1.4.3) is an essential ®lter, and that an essential ®lter is a ®lter in the sense of De®nition 1.3.4.

If no confusion is possible, the subscript on will be omitted. Notice that an essential ®lter

d is never empty; because of part (i.a), for all d, . Notice also that the application on ®lters as

in De®nition 1.3.4 is not useful for FE, since it would not be well de®ned. As in [1], application

T F must be forced to yield ®lters, since in each arrow type scheme S, is strict. E, is a cpo and henceforward it will be considered with the corresponding Scott topology.

For essential ®lters the following properties hold:

Lemma 4.2.2 i) E .

f j B M g f j B M g f j B M g F ii) e : E : . (So E : E.)

25

Proof: Easy.

F F F F F

De®nition 4.2.3 De®ne F: FE [ E E] and G: [ E E] E by:

d e

i) F d e = .

f j f g ii) G f = ( ) .

It is easy to check that F and G are continuous.

F

Theorem 4.2.4 E, , with F and G as de®ned in 4.2.3, is a -model.

F

Proof: By [5].5.4.1 it is suf®cient to prove that F G=Id[FE E].

f d f j d f j f g g

F G = [ ( ) ] =(4.2.2(i))

j d f g f d

f [ ( )] = ( ).

F F F F Remark that between E and S the same relation exists as between and S, as discussed

after De®nition 1.4.3. F

De®nition 4.2.5 Let be a valuation of term variables in E.

F [[M ]]

i) , the interpretation of terms in E via is inductively de®ned by:

x

[[x]]

a) = ( ).

M N

[[MN ]] [[ ]] [[ ]]

b) = F .

d F M

[[xM ]] [[ ]]

c) = G ( . ). dx

E ( )

B fx j x g

ii) = : ( ) .

M f j B M g

Theorem 4.2.6 For all M , : [[ ]] = : . E

Proof: By induction on the structure of lambda terms.

x fy j y g x x [[x]]

i) = ( ). Since : ( ) E : ( ).

f j B N B M g

[[MN ]]

ii) = [ E : & E : ] = (2.5(ii) & (iv))

f j B MN g

e : = (4.2.2(ii))

f j B MN g

E :

[[xM ]]

iii) =

f j B M g

: = (2.5(iv))

x

( ) E

f j B M g B B nx

: = ( = )

x e

( )

f j B fx j g M g

: e : = (4.2.2(i))

fx f j B g M g

: e : = (2.5 (iii))

f j B xM g

e : = (2.5(vi))

f j B xM g : = (2.5 (iii) & 4.2.2(ii))

e

f j B xM g

E : .

26 4.3 Soundness and completeness

In this subsection completeness for the E system will be proved. This is done in a way very

similar to the one used in [6], using the essential ®lter -model as de®ned in the previous subsection.

B M B M Theorem 4.3.1 Soundness. E : s : . Proof: By induction on the structure of derivations.

The method followed in [6] for the proof of completeness of type assignment is to de®ne a

fd F j dg

simple type interpretation that satis®es: for all types , ( ) = . The approach

taken here is to de®ne a type interpretation, and to show that it is simple.

T F fd F j dg

De®nition 4.3.2 i) 0 : S ( E) is de®ned by: 0 ( ) = E .

x f T j B x g

ii) B ( ) = S E : .

Theorem 4.3.3 i) The map 0 is a simple type interpretation.

ii) If E , then 0 ( ) 0 ( ).

Proof: i) It is suf®cient to check the conditions of De®nition 1.3.5(ii).

e e d e

a) [ 0 ( ) 0 ( )] (4.2.1 (iii))

e e f j e d g

[ 0 ( ) [ ] 0 ( )] (4.3.2(i))

e e f j e d g T

[ [ ] ] ( s)

e e e d e

[ [ ]] (for , take = )

d . b) Trivial.

ii) Easy.

B M B M

Lemma 4.3.4 i) : : .

E B E

F B

ii) E, B , 0 s .

x x

Proof: i) Because for every , B ( ) is an essential ®lter.

B f j B x g x

x [[ ]]

ii) : ((i)) : .

B B E

fd F j dg

[[x]]

So = ( ). B E 0

Since the interpretation of terms by their derivable types gives a -model, the following

corollary is immediate and an alternative proof for Theorem 2.10.

N M B M B N

Corollary 4.3.5 If = and E : , then E : .

M N M N

F [[ ]] [[ ]]

B B

Proof: Since is a -model, if = , then = ;

E

j B M g f j B N g

so f E : = E : . Notice that because of the way in which E is de®ned, Corollary 4.3.5 also holds if E is

replaced by e .

27

T B M B M

Theorem 4.3.6 Completeness. Let S, then s : E : .

B M

Proof: s : (1.3.6 (ii.c.2), 4.3.4(ii) & 4.3.3)

F M

E, B , 0 s : (1.3.6(i))

[[M ]]

( ) (4.3.2(i))

B 0

M

[[ ]]

(4.2.6)

B

B M : (4.3.4(i))

B E

M B E : .

Using the relation between the two notions of type assignment that was de®ned in the previous subsection, soundness and completeness of essential type assignment can also be proved using the

result of [6] (Property 1.3.7).

Theorem 4.3.7 Soundness and completeness of essential type assignment. Let B and contain

T B M B M

types in S. Then E : s : .

B M B M B M

Proof: ) E : : (1.3.7(i)) s : .

B M B M B M ) s : (1.3.7(ii)) : (4.1.5) E : .

5 Systems with principal types

It is well known that Curry's system has the principal type property: M is typeable if and only if

P i M

there is a pair h of basis and type, called the principal pair for , such that:

P M

: , and

hB i B M

for every pair such that : , there exists an operation O (from a speci®ed set of

P i hB i

operations) such that O (h ) = . M The type is then called the principal type for . For Curry's system the operation O consists entirely of substitutions, i.e. operations that replace type-variables by types. Principal type schemes for Curry's system are de®ned by J.R. Hindley in [21]. In this paper the author actually proved the existence of principal types for an object in Combinatory Logic, but the same construction can be used for a proof of the principal type property for terms in Lambda Calculus. The basic idea used in [21] is to de®ne a uni®cation-algorithm, that is used to construct the principal type for an application form the principal types deduced for its components. Since substitution is an easy

operation, in Curry's system the set

B i j B M g fh :

can be computed in a simple way from the principal pair for M . There exist three intersection systems for which the principal type property is proved: a CDV- system in [9], the BCD-system in [34], and the strict system in [4]. The technique used for the proofs of these properties is very different for the one used for Curry's sytem. The principal type scheme for a term is in [9], [34], and [4] studied through the notion of approximant of a term; terms with a ®nite number of approximants have ®nite principal type schemes, while terms with a in®nite number of approximants have `in®nite' principal type schemes. It should be noted that, using intersection types, also terms without normal form or, in particular, terms that have an

28 `in®nite' normal form have types. Therefore, a functional characterization of these terms, through a principal type, cannot be represented in a ®nite way.

5.1 The operation of expansion

As mentioned in the introduction of [9], using intersection types different types can be assigned to the same component of a given term. Therefore, the structure of derivation does not follow the syntactic structure of terms, and with the only operation of substitution, for a given term, not all types can be obtained. This dif®culty is overcome in [9] by introducing the (context-dependent) operation of expansion. The de®nition of expansion is very complicated. It is an operation on types that deals with the replacement of (sub)types by a number of copies of that type. Expansion on types corresponds

to the duplication of (sub)derivations: a subderivation in the right-hand side of an ( E)-step is expanded by copying. In this process, the types that occur in the subderivation are also copied: the types in the conclusion and in the basis of the subderivation will be instantiated into a number of copies.

Suppose the following is a correct derivation:

B

A

A

x

: N :

xN :

then, in general, the expansion that replaces by 1 n creates the following derivation:

B B

1 n

A A

A A

x

N

N : n

1 : 1 : n

xN :

n

Suppose that is a subtype of that is expanded into copies. If is also a subtype of ,

then just replacing by an intersection of copies of , would generate ( 1 n ). This is a

not a legal type in [9] and [4]. De®ning an operation of expansion by saying that it should expand

the subtype into the type ( 1) ( n ) ± which is by de®nition of the relation a

type equivalent to ( 1 n ) ± would give an expansion that is sound, but not suf®cient. The

n n

subtype will, therefore, be expanded into ( 1 1) ( n ), where the 1 are

copies of . This means that also all other occurrences of should be expanded into 1 n ,

with possibly the same effect on other types. Apparently, the expansion of can have a more than local effect on . Therefore, the expansion of a type is de®ned in a such a way that, before the replacement of types by intersections, all sub-

types are collected that are affected by the expansion of . Then types are traversed top down, and types are replaced if they end with one of the sub-types found.

5.2 The systemof [9]

In [9] principal type schemes are de®ned for a type assignment system that is like the restricted one from [10], but uses the set of types of the unrestricted system. The reason to not use the normalized

29

types as well is the fact that is treated as a type constant; since can be substituted for in

, also is considered a type. The principal type property is achieved by de®ning principal pairs of basis and type for terms in -normal form, specifying the operations of expansion and substitution, proved suf®cient to generate all possible pairs for those terms from their principal pair, and generalizing this result to arbitrary lambda terms. This technique is the same as for

example used in [34], [4], and Section 6 of this paper.

N A

The set of ground pairs for a term A , as de®ned in [9], is proved to be complete for , in A the sense that all other pairs for A can be generated from a ground pair for . Ground pairs are those that express the essential structure of a derivation, and types in it are as general as possible with respect to substitutions.

The proof of the principal type property is obtained by ®rst proving the following:

B A A N hB i A

If : with , then there is a substitution Sub and a ground pair for such

B i hB i

that Sub (h ) = .

hB i A N hB i hB i

If is a ground pair for and can be obtained from by an expansion,

B i A

then h is a ground pair for .

A N A A

For all , every ground pair for is complete for . N

In the construction of principal pairs for lambda terms, ®rst for every A a particular pair

P

Pp (A) is chosen of basis and type , called the principal basis scheme and principal type scheme A of A, respectively (see De®nition 6.1.5). This pair is called the principal pair of .

The proof is completed by proving:

A A

Pp ( ) is a ground pair for .

B M A A M B A

: if and only if there exists ( ) such that : .

f A j A A M g M Pp ( ) ( ) is complete for .

For an example of a ground pair, and its relation to the operation of expansion, take the pair

i xx y y

h ( ( 0 0) 1) 1 , which is the principal pair of ( ( )).

y

[x : ( 0 0) 1] [ : 0]

y y

x :( 0 0) 1 : 0 0

y y

x ( ) : 1

y y

xx ( ):( ( 0 0) 1) 1

Let Exp be the expansion that copies the subderivation for y y : 0 0, then

i

Exp (h ( ( 0 0) 1) 1) =

i

h ( ( 2 2) ( 3 3) 1) 1 ,

y y

which is, by the results mentioned above, a ground pair for ( xx ( )).

y y

[x : ( 2 2) ( 3 3) 1] [ : 2] [ : 3]

x y y

:( 2 2) ( 3 3) 1 y y : 2 2 : 3 3

y y

x ( ) : 1

y y xx ( ):( ( 2 2) ( 3 3) 1) 1 (See De®nition 6.2.5.)

30 5.3 The system of [34]

For the system as de®ned in [6], principal type schemes can be de®ned as in [34]. There three operations are provided ± substitution, expansion, and rise ± that are sound and suf®cient to

generate all suitable pairs for a term M from its principal pair.

In this paper, all constructions and de®nitions are made modulo the equivalence relation . In fact, the complexity inserted in the type language of [6] by allowing for intersection types on the right of the arrow type constructor, disturbs greatly the accessibility of this paper. As shown in Section 6, the results of [34] can also be obtained for the essential system presented here, that is equally powerful.

The ®rst operation de®ned is substitution, that is de®ned without restriction: the type that is to T

be substituted can be every element of . Next, the operation of expansion is de®ned, which is a generalization of the notion of expansion de®ned in [9]. Both substitution and expansions are in the natural way extended to operations on bases and pairs. The third operation de®ned (on pairs)

is the operation of rise: it consists of adding applications of the derivation rule ( ) to a derivation.

All de®ned operations are sound in the following sense:

A N B B A

(Soundness) Let for , be such that : , O be an operation of substitution,

hB i hB i B A

expansion or rise, and O ( ) = . Then : .

Linear chains of operations are de®ned as sequences of operations that start with a number of expansions, followed by a number of substitutions, and that end with one rise. (In [34], linear chains are de®ned as those sequences of operations that start with a number of expansions, followed by a number of substitutions or rises; both are allowed. This de®nition is not complete, in the sense

that the fact that the chain ends with one rise is essential in the proof for completeness.) As in [9],

principal pairs are de®ned for terms in -normal form. The proof of the principal type property M

is completed by, using the above approximation theorem, proving ®rst that, when A( ) is ®nite,

A j A A M g then fPp ( ) ( ) has a maximal element (see Theorem 6.3.4 and De®nition 6.3.5). The

following is proved:

A N hB i B A

Property 5.3.1 i) (Completeness) Let . For any pair such that : there exists

hB i

a linear chain C such that C (Pp (A)) = .

B M

ii) Let : .

M f A j A A M g hP i

a) A( ) is ®nite. Then Pp ( ) ( ) has a maximal element, say . Then there

P i hB i

exists a chain C, such that C (h ) = .

M hP i f A j A A M g

b) A( ) is in®nite. Then there exist a pair Pp ( ) ( ) and a chain C, such

P i hB i that C (h ) = .

5.4 The systemof [4]

The proof of the principal type property for the strict system as presented in [4] is achieved in a way similar to, but signi®cantly different from, the two techniques sketched above. In that paper, three operations on pairs of basis and types are de®ned: substitution, expansion, and lifting. The operation of lifting resembles the operation of rise as de®ned in [34], the operation of substitution is a modi®cation of the one normally used, and the operation of expansion coincides with the one

31 given in [9,34]. In order to prove that the operations de®ned are suf®cient, three subsets of the set of all pairs of basis and type are de®ned, namely: principal pairs, ground pairs, and primitive pairs. (The de®nition of ground pairs coincides with the one given in [9].) In that paper is shown that these form a true hierarchy, that the set of ground pairs for a term is closed under the operation of expansion, that the set of primitive pairs is closed under the operation of lifting, and that the set of pairs is closed for substitution.

The main result of that paper is reached by showing that the three operations de®ned are

B i A hP i complete: if h is a suitable pair for a term in -normal form, and is the principal

pair for A, then there are a sequence of operations of expansion Exp, an operation of lifting Lift,

and a substitution Sub, such that

!

B i hP i h = Sub (Lift (Exp ( ))).

Finally, this result is generalized to arbitrary lambda terms.

Because of technical reasons, substitution is in [4] de®ned as ( ), where is a type-

T f g variable and s , so it can also replace type-variables by the type constant (this is not needed in the proofs of Section 6). Although substitution is normally de®ned on types as the

operation that replaces type-variables by types, for strict types this de®nition would not be correct.

For example, the replacement of by would transform (or ) into ( ), which is not a strict type. Therefore, for strict types substitution is not de®ned as an operation that replaces type-variables by types, but as a mapping from types to types, that, in a certain sense, `normalizes while substituting'. The operation of expansion, as de®ned in [4], corresponds to the one given in [9] and is a simpli®ed version of the one de®ned in [34]. A difference is that in those de®nitions subtypes are collected, whereas the de®nition of expansion in [4] (see De®nition 6.2.5) collects type-variables.

Recall De®nition 2.1. Observe that strict type assignment is not closed for the relation E, so

the following does not hold:

M B M

If B S : and E , then S : .

x g x

As a counter example, take f : s : . Notice that E , but it is impossible

x g x to derive f : S : .

The operation of lifting as de®ned in [4] (see De®nition 6.2.16) is based on the relation E, in

the same way as the operation of rise is based on . As shown there, and illustrated above, that

B i operation is not sound on all pairs h . (In fact, as argued in [4], it is impossible to formulate an operation that performs the desired lifting and is sound on all pairs.) The reason for this is

that introducing a derivation rule, allowed on all terms, using the relation E, corresponds to a

-reduction step (see Theorem 2.8), and the strict system is not closed for -reduction. Since strict type assignment is not closed for E , and the operation of lifting applies E to a derivation, it is clear that a con¯ict arises. However, in [4] it is shown that the operation de®ned there is sound on primitive pairs. The de®nition for primitive pairs is based on the de®nition of ground pairs as given in [9]. The main difference between ground pairs and primitive pairs is that in a primitive pair a predicate for a term-variable (bound or free) is not the smallest type needed, but can contain some additional, irrelevant types. The problem mentioned above is then solved by allowing liftings only on primitive

32 pairs for terms. The result of [4] follows from:

Every principal pair is a ground pair.

hB i A hB i hB i

± For every expansion Exp, if is a ground pair for and Exp ( ) = , then

B i A

h is a ground pair for .

A hB i hB i B A ± If B S : and Exp ( ) = , then S : .

Every ground pair is a primitive pair.

A N hB i A hB i For all , liftings Lift: if is a primitive pair for , then Lift ( ) is a primitive

pair for A.

Every primitive pair is a (normal) pair.

B A hB i hB i B A If S : , then for every substitution Sub: if Sub ( ) = , then S : .

Although lifting is not sound on all pairs, using the results mentioned above it is possible to

B i

prove that the three operations de®ned in [4] are suf®cient (complete): for every pair h and

N B A

A , if S : , then there exists a number of expansion, one lifting, and a substitution, such

B i A that h can be obtained from Pp ( ) by performing these operations in sequence. As in [34], this result is then generalized to arbitrary lambda terms (see Property 5.3.1 and Theorem 6.3.6).

6 Principal type property for the essential system

Using a technique different from those discussed above, in this section the proof for the principal type property of the essential system will be given. For each lambda term the principal pair (of basis and type) will be de®ned. Four operations on pairs of basis and types will be de®ned, namely expansion, covering, substitution, and lifting, that are correct and suf®cient to generate all derivable pairs for lambda terms in the essential system.

A relevant restriction of the essential system will be presented ( R ), that is close to the system

de®ned in De®nition 1.2.3. For this system, the principal type property will be proved, using a

M hP i technique different from the one used in [9]. In fact, it will be shown that, if B R : and

is the principal pair for M , then there is a chain C of operations, consisting of expansions, one

P i hB i covering, and one substitution, such that C (h ) = . Using this result, the principal type property for the essential system will be proved. In [4], the main problem to solve was to ®nd an operation of lifting that was able to take the

special role of the relation S into account. As argued in Subsection 5.4, for the strict system there exist no operation of lifting that is sound on all pairs. Since the essential system is more

liberal than the strict one, in the sense that the essential system is closed for the relation E , the operation of lifting as de®ned in [4] is a sound operation for the essential system (see Theorem 6.2.17). It is then easy to show that, with just the operations as de®ned in [4], the principal type property holds for the essential system. In this subsection a different proof will be presented, that follows a new approach. The most signi®cant difference between proofs for the principal type property made in other papers and the one presented here, is that, in a certain sense, the operations presented in this section are more elegant. In [34], there is an overlap between operations; for example, intersections can be introduced by expansions as well as by substitutions and rise. Also, in [4] the step from the

33

B i hB i pair h to can be made using a lifting as well as a substitution. The operations of expansion, covering, and substitution as de®ned in this paper are `orthogonal' in that sense; no of operation can be mimicked by another kind of operation. The difference between the operations speci®ed in [4] and this paper lie in the fact that here the operation of substitution has been changed, in a subtle, natural, but drastic way: a substitution can

no longer replace a type-variable by . In the papers discussed above that possibility existed and, especially in [9] and [4], caused inconvenience, since there a `normalization-after-substitution' was called for, explicitly de®ned in [9], and part of the de®nition of substitution in [4]. The approach of this paper will be to allow of only substitutions of type variables by strict types, and to introduce

a separate operation of covering, that deals with the assignment of to subterms.

6.1 Relevant intersection type assignment

The next de®nition presents a restricted variant of the essential system, that is similar to that of De®nition 1.2.3, and is the system used in [19]. Since bases play a more signi®cant role in this system, the presentation of the derivation rules differs from the one used above.

De®nition 6.1.1 i) Relevant intersection type assignment and relevant intersection derivations are

de®ned by the following natural deduction system (where all types displayed are in Ts, except

for in rules ( E) and ( I)):

M B N

B1 R : 2 R :

x g x

(Ax): f : R : ( E):

B B g MN

Πf 1 2 R :

M M B B n : n :

1 R 1 R

n

(I): ( 0)

B B g M Πf n

1 n R : 1

B M M B x: R : R :

( I): (a)

xM B xM

B R : R : B

(a) If x does not occur in .

B M B M ii) R is de®ned by: R : if and only if there is a relevant derivation that has R :

as conclusion.

M M Notice that, by rule ( I), R : , for all terms . Notice moreover, that this system is indeed relevant, in the sense that only those statements occur in bases that are actually used for the derived statement.

For terms in N , the relation between the essential and the relevant system is formulated by:

B A B B A

Lemma 6.1.2 If A is in -normal form and E : , then there are such that R : ,

B B E and E .

Proof: By induction on the structure of terms in N .

B i) B : , then = , and = .

34

xA A B fx g A B

ii) B E : , with = , then : E : . By induction, there are such

B fx g B fx g B fx g A

that E , : E : , and : R : . Then also E ,

B B xA

B E , and R : .

B xA A n i n B A

n n i

iii) E 1 : , with 0. Then there are 1 such that, for 1 , E i : ,

B x i n B n

and : . By induction, for every 1 , there are i , such that

E 1 i

Π B A B B B fB B fx gg

n

i i i

i : , , and . Then also : ,

n i

R i E E E 1 1

fB B fx xA A gg Π n and n : : . 1 1 n R 1

Using the same technique as in Subsection 3.2, the following theorem can be proved.

M A A M B A Theorem 6.1.3 B R : ( )[ R : ].

Using this approximation result for the relevant system, the following becomes easy.

M B B M B B

Theorem 6.1.4 If B E : , then there are such that R : , E and E .

M A A M B A

Proof: If B E : then, by Theorem 3.2.7, there is an ( ) such that E : . By

B A B B

Lemma 6.1.2, there are B such that R : , E and E . Then, by Theorem 6.1.3,

M

B R : . N

In the construction of principal pairs for lambda terms, ®rst, for any A , a particular pair

P Pp (A) of basis and type is chosen, which will be called respectively the principal basis

scheme and principal type scheme of A. Principal pairs for the relevant, and the essential system

are de®ned by:

N A A

De®nition 6.1.5 i) Let A . Pp ( ), the principal pair of , is de®ned by:

h i

a) Pp () = .

hfx g i

b) Pp (x) = : .

A hP i

c) If A = , and Pp ( ) = , then:

A x P xA hP nx i

1) If x occurs free in , and : , then Pp ( ) = .

hP i

2) Otherwise Pp (xA) = .

i n A hP i

i i

d) If for 1 , Pp ( i ) = (disjoint in pairs), then

xA A hΠfP P fx gg i

n n

Pp ( 1 n ) = 1 : 1 ,

A i n

where is a type-variable that does not occur in Pp ( i ), for 1 .

fhP i j A N A hP i g ii) P = [Pp ( ) = ] .

The following result is almost immediate:

hP i P A P A Lemma 6.1.6 If Pp (A) = , then R : and E : . Proof: Easy.

The notion of principal pairs for terms in N will be generalized to arbitrary lambda terms in De®nition 6.3.5.

35 The principal pairs in the systems as presented in [9], [34], and [4] are exactly the same.

Since the essential type assignment system is a sub-system of the BCD-system (in the sense that

B M B M if E : , then also : , but not vice-versa), and it is a super-system for both the strict and the restricted CDV-system, it not surprising that the principal pairs in the essential system turn out to be exactly the same as the principal pairs in all the other systems.

6.2 Operations

Substitution is normally de®ned on types as the operation that replaces type-variables by types, without restriction. The notion of substitution de®ned here replaces type-variables by strict types only. Although this is a severe restriction with regard to the usual approach, the operation will

proven to be suf®cient.

T T T De®nition 6.2.1 i) The substitution ( ) : S S, where is a type-variable and s, is

de®ned by:

a) ( )( ) = .

b) ( )( ) = , if .

c) ( )( ) = ( )( ) ( )( ).

n

d) ( )( 1 n ) = ( )( 1) ( )( ).

ii) If Sub1 andSub2 aresubstitutions,thensoisSub1 Sub2, whereSub1 Sub2 ( ) =Sub1 (Sub2 ( )).

fx j x B g

iii) Sub (B ) = :Sub ( ) : .

B i h B i iv) Sub (h ) = Sub ( ) Sub ( ) .

The operation of substitution is sound for the relevant system.

A hB i hB i

Theorem 6.2.2 If B R : , then for every substitution Sub: if Sub ( ) = , then

A B R : .

Proof: By straightforward induction on the de®nition of R.

The following is needed in the proof of Theorem 6.3.3.

T

Lemma 6.2.3 Let s and Sub be a substitution such that Sub ( ) = . Then:

fx g B fx g hB i hB i

i) If Sub (B : ) = : , then Sub ( ) = .

i n hB i hB i i

ii) If for every 1 , Sub ( i ) = , then

i i

hΠfB B fx gg i n

Sub ( 1 n : 1 ) =

hΠfB B fx gg i

: . n 1 n 1 Proof: Immediately by De®nition 6.2.1.

The operation of expansion of types de®ned here corresponds to the notion of expansion as de®ned in [34] and [4]. A difference between the notions of expansion as de®ned in [9] and [34] is that in those papers a set of types involved in the expansion is created. As in [4], here just type-variables are collected, so the de®nition of expansion presented here is less complicated.

36

T T

De®nition 6.2.4 i) If B is a basis and , then is the set of all strict subtypes occurring

B i

S h

B i in the pair h .

ii) The last type-variable of a strict type is de®ned by:

a) The last type-variable of is .

b) The last type-variable of 1 n is the last type-variable of .

T n B T h n B i

De®nition 6.2.5 For every s, 2, basis , and S, the quadruple determines T

an expansion Exp : T , that is constructed as follows.

nB i

h S S

V hB i

i) The set of type-variables ( ) affected by Exp is constructed by:

hnB i

V hB i

a) If occurs in , then ( ).

T V hB i

b) If the last type-variable of is in ( ), then for all type-variables that

hB i

V hB i

occur in : ( ).

1 n

V hB i f g m n

ii) Suppose ( ) = . Choose different type-variables , , , ,

1 m 1 1 i

1 n

hB i i n j m

, , , such that each does not occur in , for 1 and 1 . Let, for

m m

j

i

i n j m i

1 , Subi be such that Sub ( ) = , for 1 .

j

j

iii) Exp ( ) is obtained by traversing top-down and replacing every subtype by

hnB i

V hB i n

Sub1 ( ) Sub ( ), if the last type-variable of is in ( ), i.e.:

n

a) Exp ( n ) = Exp ( ) Exp ( ).

nB i hnB i hnB i

h 1 1

V hB i n

b) If the last type-variable of is in ( ), then Exp ( ) =Sub ( ) Sub ( ).

nB i h 1

c) Otherwise,

1) Exp ( ) = Exp ( ) Exp ( ).

hnB i hnB i hnB i

2) Exp () = .

hnB i

fx j x B g

iv) Exp (B ) = :Exp ( ) : .

hnB i hnB i

B i h B i

v) Exp (h ) = Exp ( ) Exp ( ) .

hnB i hnB i hnB i

n B i

Instead of Exp , the notation h will be used.

hnB i

Example 6.2.6 Let be the type ( 1 2) ( 3 1) 3 2, and Exp be the expansion

h i V h i f g

1 2 . Then 1 ( ) = 1, 3 , and

Exp () = (( 4 5) 2) (( 6 4) ( 7 5)) ( 6 7) 2.

i h i xy z x y z

Notice that both h and Exp ( ) are pairs for the term ( ) in E:

z

y : 3 1 : 3

x

: 1 2 y z : 1

y z

x( ) : 2

y z

z x( ) : 3 2

y z

y z x( ):( 3 1) 3 2

y z xy z x( ):( 1 2) ( 3 1) 3 2

37

z z

y

:( 6 4) ( 7 5) : 6 7 y :( 6 4) ( 7 5) : 6 7

y

y z

: 6 4 : 6 : 7 5 z : 7

y z

y z

x :( 4 5) 2 : 4 : 5

y z

x( ) : 2

y z

z x( ):( 6 7) 2

y z

y z x( ):(( 6 4) ( 7 5)) ( 6 7) 2

y z xy z x( ):(( 4 5) 2) (( 6 4) ( 7 5)) ( 6 7) 2

For an operation of expansion the following property holds:

h n B i i

Lemma 6.2.7 Let Exp = be an expansion. Exp ( ) = 1 n with for every 1

T n

, i is a trivial variant of , or Exp ( ) s.

Proof: Immediately by De®nition 6.2.5.

The following lemmas are needed in the proofs of the following theorems. The ®rst states that if the last type-variable of the type in a pair is affected by an expansion, then all type-variables in

that pair are affected.

A T h n B i

Lemma 6.2.8 Let B R : , where s with last type-variable , and be an expan-

T T V hB i 0

sion such that . If ( ), then, for every type-variable that occurs in

hB i hB i

hB i V hB i

, ( ).

Proof: By induction on the structure of elements of N .

A x B fx g V hB i

i) , then = : . Since the last type-variable of is in ( ), and

T T

,

g i hB i x

hf :

V hB i

all type-variables that occur in are in ( ).

xA B fx g A B fx g B

ii) A , then = , and : R : (if = , then : = ). Since the

last type-variable of is the last type-variable of , and

T T T 0

0 ,

hB fx g i hB i hB i

:

hB fx g i V hB i

by induction, all type-variables in : are in ( ). So all type-variables in

hB i V hB i

are in ( ).

A xA A B B j m

m m

iii) 1 m . Then there are 1 , 1, , , such that for every 1 ,

B A B ΠfB B fx gg

m m

j j

j R : , and = 1 : 1 . Since the last type-variable of

V hB i

is in ( ), and

T T

m ,

ΠfB B fx gg i hB i h m

1 0 m : 1 k

1 j

V hB i j m

m

every type-variable in is in ( ). If, for 1 , j = , j

1 j

l

l k V hB i

then, for every 1 j , the last type-variable of is in ( ), and

j

T T T

l ,

h ΠfB B fx gg i hB i

m m

B i h :

j 0 1 j

38

l

i hB V hB i j m l k

j

so all type-variables in j are in ( ), for1 ,1 . So all type-variables

j

hΠfB B fx gg i V hB i

m

in 1 m : 1 are in ( ).

A T h n B i

Lemma 6.2.9 Let B R : , where s, and Exp = be an expansion such that

T T B B

0 n

. Then either there are n , , such that

B i hB i

h 1 1

hB i hΠfB B g i n

Exp ( ) = 1 n 1

i n hB i hB i hB i hB i i

and, for every 1 , i is a trivial variant of , or Exp ( ) = , with

Ts.

Proof: By Lemmas 6.2.7, and 6.2.8.

B i hB i Notice that, in particular, this lemma holds for the case that h = . The following property is needed in the proofs for the fact that expansion is sound (Theorem

6.2.11), and for completeness of chains of operations (Theorem 6.3.3).

T

Property 6.2.10 ([4]) Let Exp be an expansion, s such that the last type-variable of is not

affected by Exp, and Exp ( ) = . Then:

B fx g i hB fx g i hB i hB i

i) Exp (h : ) = : , if and only if Exp ( ) = .

hB i hB i i n i

ii) Let Exp ( i ) = , for every 1 . Then

i i

hΠfB B fx gg i n

Exp ( 1 n : 1 ) =

ΠfB B fx gg i

h : . n 1 n 1

The following theorem states that expansion is sound for relevant type assignment.

A hB i hB i

Theorem 6.2.11 If B R : and Exp an expansion such that Exp ( ) = , then

A

B R : .

T Proof: By induction on the de®nition of R , of which only the part s is shown. By Lemma

6.2.9 either:

B ΠfB B g hB i hB i

m m i

i) = 1 , = 1 , and each i is a trivial variant of and,

B A B A i therefore, i R : . So,byrule ( I), R : .

or

T N

ii) s. This part is proved by induction on the structure of elements of . Notice that the case

that A need not be considered.

xA B fx g A

a) A , = , and : R : . Let = . (Notice that, if = , by

hB fx g i hB fx g i

De®nition6.2.5, also = ). By Lemma6.2.10(i), Exp ( : ) = : ,

fx g A B xA

and, by induction, B : R : . Then also R : .

A xA A n B ΠfB B fx gg B A

n n n

i i

b) 1 , with 0, = 1 : 1 , and i R : ,

i n i n hB i hB i i i

for 1 . Let, for 1 , Exp ( i ) = , then, by induction, for every 1

i i

n B A

, j : . Then, by Lemma 6.2.10 (ii), i

i R

hΠfB B fx gg i n

Exp ( 1 m : 1 ) =

hΠfB B fx gg i

: . n 1 m 1

39

ΠfB B fx gg xA A

Then : m : . n 1 m 1 R 1

The third operation on pairs de®ned in this section is the operation of covering. It is, unlike

the de®nition of lifting and rise, not de®ned on types, but directly on pairs, using the relation <

de®ned on pairs. This relation is inspired by the relation on terms in N , and the relation between 

the principal pairs of two terms that are in that relation (see also Theorem 6.3.4).

De®nition 6.2.12 The relation on pairs is de®ned by:

B i h i

i) h .

i n n hB i hB i i

ii) 1 ( 2) [ i ]

i i

h ΠfB B g i hΠfB B g i n

n . n

1 1 1 n 1

B fx g i hB fx g i hB i hB i

iii) h : : .

i n hB i hB i i

iv) 1 [ i ]

i i

hΠfB B fx gg i n

1 n : 1

ΠfB B fx gg i

h : . n

1 n 1

hB i hB i

De®nition 6.2.13 A covering Cov is an operation denoted by a pair of pairs 0 0 1 1

B i hB i

such that h 0 0 1 1 , and is de®ned by:

B i hB i hB i hB i

Cov (h ) = 1 1 , if = 0 0 ,

B i = h , otherwise.

As mentioned above, the operation of covering de®ned here is inspired by the relation < on 

terms in N , and, in fact, is very close to a notion de®ned in [27]. In that paper principal typings for the type assignment system as presented in [25] are studied. That system is a combination of the BCD-system and the polymorphic type discipline as presented in [20], and can be seen as an

extension of the BCD-system by adding quanti®cation over type-variables.

A

In [27], for every in -normal form a relation A is de®ned on the inductively de®ned

B i A B A

set of pairs h admissible for (i.e. such that : ). This relation satis®es:

hB i hB i A

If 1 1 A 2 2 , then both pairs are admissible for .

hB i hB i

It is, for example, straightforward to show that 1 1 A 2 2 , when restricted to E ,

hB i hB i A

implies 1 1 2 2 . Notice that the structure of a term is present in the relation A , but absent in , although of course De®nition 6.2.12 follows in part the syntactic structure of

terms in N (part (iii) and (iv)).

The operation of covering is not sound for E.

x g i hfx g i

Example 6.2.14 It is easy to check that hf : ( ) : . Notice that the ®rst

x g x fx g x pair is legal since f : ( ) E : is derivable, but not : E : .

The operation of covering is sound for the relevant system.

hB i hB i B A B A Theorem 6.2.15 For every covering , if R : , then R : .

40

Proof: By induction on the structure of types.

B

i) = , = . Trivial.

n B ΠfB B g n ii) = , 2. Then = n , = , and, for every 1

1 n 1 1

B A B ΠfB B g i n i n i

, i : . By De®nition 6.2.12 (ii), = , and, for every 1 ,

R 1 n

i hB i hB B A B A i

i is a covering. Then, by induction, : ,soalso : .

n

i i i

i R R 1

T A

iii) s. By induction on .

xA B xA B x A

a) A . If R : , then = , : R : , and = . Since

hB i hB i hB fx g i hB fx g i

is a covering, also : : is a cov-

x A B xA

ering, so, by induction, B : R : , so R : .

A y A A n B y A A B B

n n n

b) 1 n , with 0. Since R 1 : , there are 1, , , 1 ,

B ΠfB B fx gg B A i n

n n

i i

such that = 1 : 1 , and i R : , for every 1 .

i B B i n hB i hB i

Then there are , , such that for every 1 , i is

n n i

1 1 i

ΠfB B fx gg i

a covering, and B = : . Then by induction, for 1 n

1 n 1

B A ΠfB B y A A fx gg n n

, i : , so also : : .

n n i i R 1 1 R 1

The last operation needed in this paper is that of lifting, as ®rst presented in [4]:

hB i hB i

De®nition 6.2.16 A lifting Lift is an operation denoted by a pair of pairs 0 0 , 1 1 such

B B

that 0 E 1 and 1 E 0, and is de®ned by:

i) Lift ( ) = 1, if = 0; otherwise, Lift ( ) = .

B B B B B

ii) Lift (B ) = 1, if = 0; otherwise, Lift ( ) = .

B i h B i iii) Lift (h ) = Lift ( ) Lift ( ) .

The operation of lifting is sound for essential type assignment.

M hB i hB i

Theorem 6.2.17 If B E : and , is a lifting, then

M

B E : .

B Proof: By de®nition 6.2.16, B E , and E . The proof follows from Lemmas 2.5 (vii) and

2.6.

hB i hB i

Notice that the de®nition of covering differs from that of lifting, in that 0 0 , 1 1

B

is a lifting only if B1 E 0 and 0 E 1. For a covering, this is normally not the case.

y g i h i

Example 6.2.18 Since by 6.2.12(i) hf : ,

x y g i hfx g i

by 6.2.12(iv) also hf : : : ,

x g i hfx g i

so by 6.2.12(iii) hf : : ,

i h i

and, again by 6.2.12(iii), h ( ) ( ) ,

but not ( ) E ( ) , and neither ( ) E ( ) .

41 6.3 Completeness of operations

In this subsection, completeness of the above speci®ed operations will be proved, both for the

relevant as for the essential system. First the notion of chain of operations is introduced.

O O n De®nition 6.3.1 i) A chain is an object [ 1 ], where each Oi is an operation of expansion,

covering, substitution, or lifting, and

O O hB i hB i n [ 1 n ]( ) = O ( (O1 ( )) ).

ii) On chains the operation of concatenation is denoted by , and

O O O O O O

n n i [ 1 i ] [ +1 ] = [ 1 ]. iii) A relevant chain is a chain of expansions, concatenated with a chain consisting of at most one substitution, and at most one covering, in that order. iv) An essential chain is a relevant chain, concatenated with one operation of lifting.

The next theorem shows that for every suitable pair for a term A, there exists a chain such that the

result of the application of this chain to the principal pair of A produces the desired pair. Part (i) of the Lemmas 6.2.3, and 6.2.10 are needed for the inductive step in case of an abstraction term, part (iii.b) of the proof, part (ii) of those lemmas are needed for the inductive step in case of an application term, part (iii.c). Notice that, by construction, all operations mentioned in that part

satisfy the conditions required by these lemmas.

A A hP i

Theorem 6.3.2 If B R : and Pp ( ) = , then there exists a relevant chain C such that

P i hB i C (h ) = .

Proof: By induction on the de®nition of R.

A hP i h i i) R : . Take Cov = , which, by De®nition 6.2.13(i), is a covering. Take

C =[Cov].

B A B B i n B A B

n n i

ii) R : 1 . Then there are 1 such that for 1 , i R : , and =

B B g h n P i Πf

1 n . Let Exp = , then

hP i hΠfP P g i n

Exp ( ) = 1 n 1 ,

A hP i

n i

with Pp ( ) = i . By induction, there exist relevant chains C1, , C such that for 1

!

i n hP i hB i i n B

i i i i i i i i

, C ( i ) = . Let, for 1 , C = Exp [Sub ] [Cov ], and be such

i i

that

!

i i hB i hP i hB hB

i i i i i i

Exp [Sub ]( i ) = , and Cov = .

i i i i

Then, by De®nition 6.2.12 (ii),

hΠfB B g i hΠfB B g i n

Cov = n n 1 n 1 1 1

is a covering. Take

! !

n

C =[Exp] Exp1 Exp [Sub1 Subn ] [Cov].

A T N

iii) B R : ,so s. This part is proved by induction on the structure of elements of . Notice

that the case that A need not be considered.

x B fx g P fx g a) A . Then = : , = : , and = . Take

42

C = [( )].

xA

b) A .

FV A B x A xA

1) x ( ). Then there are such that = , : R : , and Pp ( ) =

P i A hP fx g i

h , where Pp ( ) = : . By induction there exists a relevant chain C

!

= Exp [Sub] [Cov'] such that

P fx g i hB fx g i

C (h : ) = : .

B

Let be such that

!

P fx g i hB fx g i Exp [Sub](h : ) = : ,

and

hB fx g i hB fx g i

Cov = : : .

T T

Since s, by construction also s and, by Lemmas 6.2.10(i) and 6.2.3(i),

!

P i hB i

Exp [Sub](h ) = . Take

hB i hB i Cov = ,

which, by De®nition 6.2.12 (iii), is a covering. Take

!

C = Exp [Sub] [Cov].

FV A B A xA

2) x ( ). Then there is such that = , and R : . Then Pp ( )

P i A hP i

= h , where Pp ( ) = . By induction there exists a relevant chain C =

!

Exp [Sub] [Cov'] such that

P i hB i

C (h ) = .

Let B be such that

!

hP i hB i hB i hB i

Exp [Sub]( ) = , and Cov = .

T T

Since s, by construction also s and, by Lemma 6.2.10(i), and 6.2.3(i),

!

hP i hB i

Exp [Sub]( ) = . Take

hB i hB i Cov = ,

which, by De®nition 6.2.12 (iii), is a covering. Take

!

C = Exp [Sub] [Cov].

A xA A B B j m

m m

c) 1 m . Then there are 1 , 1, , , such that, for every 1 ,

B A B ΠfB B fx gg

m m

j j

j R : , = 1 : 1 , and

P ΠfP P fx gg m

= 1 m : 1 , = ,

j m A hP i

j j

with for every 1 , Pp ( j ) = , in which does not occur. By induction, there

j m hP i hB i

m

j j j j

are relevant chains C1, , C such that, for 1 , C ( j ) = . Let, for

!

j m B

j j j

1 , Cj = Exp [Sub ] [Cov ], and be such that

j j

!

i i hB i hP i hB hB

j j j j j j

Exp j [Sub ]( ) = , and Cov = .

j j j j

! ! !

m Let Exp = Exp1 Exp , and Sub = Sub1 Subm ( ), then, because of Lem-

mas 6.2.10 (ii) and 6.2.3(ii):

!

hΠfP P fx gg i m

Exp [Sub]( 1 m : 1 ) =

hΠfB B fx gg i

: . m 1 m 1

43

Then, by De®nition 6.2.12 (iv),

hΠfB B fx gg i

Cov = : , m

1 m 1

hΠfB B fx gg i m 1 m : 1 ,

is a covering. Take

! C = Exp [Sub] [Cov].

Now, for essential type assignment the completeness of the here speci®ed operations becomes

easy to prove:

A A hP i

Theorem 6.3.3 If B E : and Pp ( ) = , then there exists an essential chain C such that

P i hB i

C (h ) = .

B A B B

Proof: By Lemma 6.1.2 there are B such that R : , E , and E . By The-

P i hB i

orem 6.3.2, there exists a relevant chain C such that such that C (h ) = . Since

hB i hB i

, is a lifting, by De®nition 6.3.1(iv), there exists an essential chain such that

P i hB i C (h ) = .

Like in [9,34,4], it can be proved that there exists a precise relation between terms in N and principal pairs, both equipped with an appropriate ordering. This relation is in [34] de®ned using

substitution of type-variables by the type constant . Using the notion of substitution de®ned here, this approach cannot be taken; instead, the relation on pairs as given in De®nition 6.2.12 is

used.

<

i hN i

Theorem 6.3.4 hP is a meet semilattice isomorphic to .

 P

Proof: Pp is, as function from N to , by De®nition 6.1.5(ii), surjective. It is injective because of

<

A A A

Theorems 4.2.4, 4.2.6, and 6.3.3. That Pp respects the order, i.e. if A , then Pp ( ) Pp ( ), 

follows by straightforward induction. Π M

De®nition 6.3.5 (cf. [34,4]) i) Let M be a term. Let ( ) be the set of all principal pairs for all

Π M f A j A A M g approximants of M : ( ) = Pp ( ) ( ) .

Π P

ii) (M ) is an ideal in , and therefore:

F

hP i Π M hP i P a) If Π(M ) is ®nite, then there exists a pair = ( ), where . This pair is

then called the principal pair of M .

Π F Π M P M b) If (M ) is in®nite, ( ) does not exist in . The principal pair of is then the in®nite

set of pairs Π(M ).

The proof of the principal type property for the essential system is completed by the following:

B M

Theorem 6.3.6 Let B and be such that E : .

M hP i M

i) A( ) is ®nite. Let be the principal pair of . Then there exists an essential chain C

P i hB i

such that C (h ) = .

M hP i Π M

ii) A( ) is in®nite. Then there exist a pair ( ) and an essential chain C such that

P i hB i C (h ) = .

44

M A A M B A

Proof: From B E : and Theorem 3.2.7 follows ( )[ E : ]. Then:

A A M M A hP i

M

i) By De®nition 6.3.5, there exists M ( ) such that Pp ( ) = Pp ( ) = . Since

A P A A A A M

M M

Pp ( M ) is minimal in , so Pp ( ) Pp ( ), by Theorem 6.3.4, is maximal in ( ),

<

A A B A M

so M . Then, by Lemma 2.5 (viii), also E : .



P i A Π M

ii) By De®nition 6.3.5, h = Pp ( ) ( ).

P i hB i In any case, by Theorem 6.3.3, there exists an essential chain such that C (h ) = .

The same result, using relevant chains rather than essential chains, can be formulated for the relevant system.

Conclusions

This paper presented the essential intersection type assignment system, as a true restriction of the BCD-system that satis®es all properties of that system, where derivations are syntax-directed. Since all properties of the BCD-system are shown to hold for the essential system, the treatment

of intersection types as in [6] has been too general. Instead of introducing as a general type- constructor, and as a type-constant, it is better to treat as the empty intersection, and to allow

intersections only on the left of the .

References

[1] S. van Bakel. Complete restrictions of the Intersection Type Discipline. Theoretical Computer Science, 102:135±163, 1992. [2] S. van Bakel. Partial Intersection Type Assignment of Rank 2 in Applicative Term Rewriting Systems. Technical Report 92-03, Department of Computer Science, University of Nijmegen, 1992. [3] S. van Bakel. Essential Intersection Type Assignment. In R.K. Shyamasunda, editor, Proceedings of FST&TCS '93. 13th Conference on Foundationsof SoftwareTechnology and Theoretical Computer Science, Bombay, India, volume 761 of Lecture Notes in Computer Science, pages 13±23. Springer-Verlag, 1993. [4] S. van Bakel. Principal type schemes for the Strict Type Assignment System. Logic and Computation, 3(6):643±670, 1993. [5] H. Barendregt. The Lambda Calculus: its Syntax and Semantics. North-Holland, Amsterdam, revised edition, 1984. [6] H. Barendregt, M. Coppo, and M. Dezani-Ciancaglini. A ®lter lambda model and the completeness of type assignment. Journal of Symbolic Logic, 48(4):931±940, 1983.

[7] M. Coppo and M. Dezani-Ciancaglini. An Extension of the Basic Functionality Theory for the -Calculus. Notre Dame, Journal of Formal Logic, 21(4):685±693, 1980. [8] M. Coppo, M. Dezani-Ciancaglini, F. Honsell, and G. Longo. Extended type structures and ®lter lambda models. In G. Lolli, G. Longo, and A. Marcja, editors, Logic Colloquium 82, pages 241±262, Amsterdam, the Netherlands, 1984. North-Holland.

[9] M. Coppo, M. Dezani-Ciancaglini, and B. Venneri. Principal type schemes and -calculus semantics. In J.R. Hindley and J.P. Seldin, editors, To H.B. Curry, Essays in combinatory logic, lambda-calculus and formalism, pages 535±560. Academic press, New York, 1980. [10] M. Coppo, M. Dezani-Ciancaglini, and B. Venneri. Functional characters of solvable terms. Zeitschrift furÈ Mathematische Logik und Grundlagen der Mathematik, 27:45±58, 1981.

[11] M. Coppo, M. Dezani-Ciancaglini, and M. Zacchi. Type Theories, Normal Forms and D 1 -Lambda-Models. Information and Computation, 72(2):85±116, 1987.

45 [12] M. Coppo and P. Giannini. A complete algorithm for simple intersection types. In J.-C. Raoult, editor, Proceedings of CAAP '92. 17th Colloquim on Trees in Algebra and Programming, Rennes, France, volume 581 of Lecture Notes in Computer Science, pages 102±123. Springer-Verlag, 1992. [13] H.B. Curry. Functionalityin combinatory logic. In Proc. Nat. Acad. Sci. U.S.A., volume 20, pages 584±590, 1934. [14] H.B. Curry and R. Feys. Combinatory Logic, volume 1. North-Holland, Amsterdam, 1958. [15] F. Damiani and P. Giannini. A Decidable Intersection Type System based on Relevance. In M. Hagiya and J.C. Mitchell, editors, Proceedings of TACS '94. International Symposium on Theoretical Aspects of Computer Software, Sendai, Japan, volume 789 of Lecture Notes in Computer Science, pages 707±725. Springer-Verlag, 1994. [16] M. Dezani-Ciancaglini and I. Margaria. F-semantics for intersection type discipline. In G. R. Kahn, D. B. Macqueen, and G. Plotkin, editors, Semantics of data types. International symposium, Sophia-Antipolis, France, volume 173 of Lecture Notes in Computer Science, pages 279±300. Springer-Verlag, 1984. [17] M. Dezani-Ciancaglini and I. Margaria. A characterisation of F-complete type assignments. Theoretical Computer Science, 45:121±157, 1986. [18] E. Engeler. Algebras and combinators. Algebra universalis, 13(3):389±392, 1981. [19] P. Gardner. Discovering Needed Reductions Using . In M. Hagiya and J.C. Mitchell, editors, Proceedings of TACS '94. International Symposium on Theoretical Aspects of Computer Software, Sendai, Japan, volume 789 of Lecture Notes in Computer Science, pages 555±597. Springer-Verlag, 1994. [20] J.Y.Girard. The System F of Variable Types, Fifteen years later. Theoretical Computer Science, 45:159±192, 1986. [21] J.R. Hindley. The principal type scheme of an object in combinatory logic. Transactions of the American Mathematical Society, 146:29±60, 1969. [22] J.R.Hindley. ThesimplesemanticsforCoppo-Dezani-SallÂetype assignment. In M. Dezani and U. Montanari, editors, Internationalsymposium on programming,volume137of Lecture Notes in Computer Science, pages 212±226. Springer-Verlag, 1982.

[23] J.R. Hindley. The Completeness Theorem for Typing -terms. Theoretical Computer Science, 22(1):1±17, 1983. [24] R. Hindley and G. Longo. Lambda calculus models and extensionality. Zeitschrift furÈ Mathematische Logik und Grundlagen der Mathematik, 26:289±310, 1980. [25] B. Jacobs, I. Margaria, and M. Zacchi. Filter Models with Polymorphic Types. Theoretical Computer Science, 95:143±158, 1992. [26] D. Leivant. Polymorphic Type Inference. In Proceedings 10th ACM Symposium on Principles of Program- ming Languages, Austin Texas, pages 88±98, 1983.

[27] I. Margaria and M. Zacchi. Principal Typing in a 8\-Discipline. Logic and Computation. To appear. [28] R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17:348±375, 1978. [29] J.C. Mitchell. Polymorphic Type Inference and Containment. Information and Computation, 76:211±249, 1988. [30] B.C. Pierce. Programming with Intersection Types and Bounded Polymorphism. PhD thesis, Carnegie Mellon University, School of Computer Science, Pitssburgh, 1991. CMU-CS-91-205. [31] B.C. Pierce. Intersection Types and Bounded Polymorphism. In M. Bezem and J.F. Groote, editors, Proceedings of TLCA '93. International Conference on Typed Lambda Calculi and Applications, Utrecht, the Netherlands, volume 664 of Lecture Notes in Computer Science, pages 346±360. Springer-Verlag, 1993. [32] J.C. Reynolds. The essence of Algol. In J.W. de Bakker and J.C. van Vliet, editors, Algorithmic languages, pages 345±372. North-Holland, 1981. [33] J.C. Reynolds. Preliminary design of the programming language Forsythe. Technical Report CMU-CS-88- 159, Carnegie Mellon University, Pitssburgh, 1988. [34] S. Ronchi della Rocca and B. Venneri. Principal type schemes for an extended type theory. Theoretical Computer Science, 28:151±169, 1984.

46 [35] P. SallÂe. Une extension de la thÂeorie des types. In G. Ausiello and C. BÈohm, editors, Automata, languages and programming. Fifth Colloquium, Udine, Italy, volume 62 of Lecture Notes in Computer Science, pages 398±410, Udine, Italy, 1978. Springer-Verlag. [36] W.W. Tait. Intensional interpretation of functional of ®nite types. Journal of Symbolic Logic, 32, 1967.

[37] C.P. Wadsworth. The relation between computational and denotational properties for Scott's D 1 -models of the lambda-calculus. SIAM J. Comput., 5:488±521, 1976.

47