Loyola University Chicago Loyola eCommons

Computer Science: Faculty Publications and Other Works Faculty Publications

1-1996

Putting Type Annotations to Work

Martin Odersky Universität Karlsruhe

Konstantin Laufer Loyola University Chicago, [email protected]

Follow this and additional works at: https://ecommons.luc.edu/cs_facpubs

Part of the Computer Sciences Commons

Recommended Citation M. Odersky and K. Läufer, Putting type annotations to work, in Proceedings of the 23rd ACM SIGPLAN- SIGACT symposium on Principles of programming languages, ser. POPL '96. New York, NY, USA: ACM, 1996, pp. 54-67. [Online]. Available: http://webpages.cs.luc.edu/~laufer/papers/popl96.pdf

This Conference Proceeding is brought to you for free and open access by the Faculty Publications at Loyola eCommons. It has been accepted for inclusion in Computer Science: Faculty Publications and Other Works by an authorized administrator of Loyola eCommons. For more information, please contact [email protected].

This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. Copyright © 1996 Martin Odersky and Konstantin Läufer

Putting Typ e Annotations to Work

Martin Odersky Konstantin Läufer

Department of Computer Science Department of Mathematical Sciences

University of Karlsruhe Loyola University Chicago

76128 Karlsruhe, Germany Chicago, Illinois 60626, USA

o [email protected] [email protected]

Abstract egories. Curry-style reconstruction lls in p olymorphic

abstractions and applications together with typ e an-

We study an extension of the Hindley/Milner system

notations. This style of reconstruction is complicated

with explicit typ e scheme annotations and typ e decla-

by the lack of principal typ es in F . The prop osed

2

rations. The system can express p olymorphic function

schemes all have rather complex inference rules with

arguments, user-dened data typ es with abstract com-

cumb ersome conversions b etween declared and inferred

p onents, and structure typ es with p olymorphic elds.

typ es [McC84, OG89]. By contrast, Church-style re-

More generally, all programs of the p olymorphic lambda

construction requires the p osition of typ e abstractions

calculus can b e enco ded by a translation b etween typ-

and applications to b e indicated in the original source.

ing derivations. We show that typ e reconstruction in

This style of reconstruction also called partial typ e

this system can b e reduced to the decidable problem of

reconstruction [Bo e89] was shown to b e reducible to

rst-order unication under a mixed prex.

higher-order unication [Pfe88]. Even though Church-

style reconstruction is thus undecidable in general, this

result op ens up the p ossibility for semi-decision pro ce-

1 Intro duction

dures that work well in practice. On the other hand,

the p osition of a p olymorphic application has to b e in-

Two of the most imp ortant cornerstones of typ e theory

dicated explicitly in the source, which leads to a rather

for programming languages are the Hindley/Milner sys-

unfamiliar co ding style, at least for programmers used

tem and the second-order p olymorphic -calculus. This

to the Hindley/Milner system.

pap er tries to explore some of the design space b etween

Recently there havebeenseveral approaches towards

them.

extending the Hindley/Milner system with some form

The Hindley/Milner system [Mil78] extends the

of emb edded quantiers without going all the wayto

simply-typ ed -calculus with p olymorphic let-b ound

the p olymorphic -calculus. For instance, Launch-

identiers. It thus adds considerable expressivepower

bury and Peyton Jones have presented an elegant

yet retains the prop erty thatnotyp e annotations in

typ e system for syntactic control of interference [LPar]

programs are needed, since most general typ es can b e

that uses second-order universal quantication. Perry

inferred [DM82]. This prop erty has made the Hind-

[Per90] and Läufer and Odersky [LO94]have studied

ley/Milner system very app ealing as a basis of typ e

existential quantication in algebraic datatyp es, which

systems for programming languages.

yields a Hindley/Milner style version of Mitchell and

By contrast, the second-order p olymorphic -

Plotkin's abstract typ es [MP88]. This style of existen-

calculus F [Gir71, Rey74] allows p olymorphic typ es

2

tial quantication has b een implemented in compilers

everywhere, but requires explicit annotations of b oth

for Hop e [Per90], Haskell [Aug94] and CAML [MP93].

argumenttyp es and typ e instantiations. The general

Rémy [Rém94] has extended Läufer and Odersky's sys-

problem of typ echecking without typ e annotations is

tem with universal quantication in datatyp es, so that

undecidable [Wel94], but there havebeenseveral ap-

ob jects with p olymorphic metho ds can b e expressed.

proaches towards typ e reconstruction where some typ e

Jones [Jon95] has investigated record typ es with p oly-

information is given. These generally fall into two cat-

morphic elements as a way to capture essential asp ects

of mo dule systems. A prop osal along these lines has

b een accepted for inclusion in Haskell 1.3.

It seems that a combination of all of the ab ove sys-

tems, while feasible, would b e rather unwieldy. Fortu-

nately, it turns out that it is go o d enough to consider as

a generalization a far simpler typ e system that captures only to typ es, never to typ e schemes. We get back

the extensions' commonalities and expresses their dif- the full p ower of F in an indirect way,by allowing

2

ferences via enco dings. The extensions all have in com- typ e schemes as comp onents of explicitly declared

mon that some form of explicit typ e information is re- data typ es. We show that we can enco de all of F

2

quired. For instance, Läufer and Odersky's and Rémy's by providing typ e declarations for all p olymorphic

systems restrict existential quantication to the com- typ es in a given F program. This shows that our

2

p onents of explicitly declared datatyp es, while Jones typing discipline provides essentially the same ca-

restricts universal quantication to elds of explicitly pabilities as F ,even though the enco ding in F

2 2

declared record typ es. do es not supp ort a formal comparison of expres-

Here we study a typ e system that allows but do es sivepower in the sense of Felleisen [Fel90] since it

not require explicit typ e scheme annotations for func- fails to b e comp ositional.

tion arguments. The idea is that a formal function pa-

Our typing discipline is a conservative extension of

rameter is p olymorphic only if annotated with a typ e

the Hindley/Milner system. Every typable program in

scheme; otherwise the parameter is monomorphic, i.e. it

that system continues to b e typable. This holds also if

has a typ e, not a typ e scheme. As an imp ortant sp ecial

typ e annotations in the style of ML or Haskell are added

case we admit a rudimentary form of user-dened data

to Hindley/Milner. Wewere able to show principal

typ e declaration that intro duces a value constructor

typ e prop erties and soundness and completeness of typ e

with a single, p ossibly p olymorphic argument. Finally,

inference fully analogous to the results stated by Damas

we also allowtyp e scheme annotations for expressions.

and Milner [DM82]. Since the engineering issues of

Note that this is roughly the of typ e annota-

ML-like programming languages and typ e checkers are

tions that most programming languages oer or require.

bynowwell understo o d, we b elieve that this makes

The crucial extension of this pap er is that annotations

our system promising as a practical kernel language on

and declarations can refer to p olymorphic typ e schemes

whichtyp e-systematic extensions of ML or Haskell can

instead of just typ es. The ramications of this simple

b e based.

idea are quite substantial.

The rest of this pap er is organized as follows. Sec-

tion 2 presents our typ e system. Section 3 shows how

 We can express p olymorphic function arguments

previous p olymorphic extensions of ML can b e em-

by annotating the argument with a typ e scheme.

b edded in it. Section 4 discusses an enco ding of the

 We can express data typ es and record typ es by

p olymorphic -calculus. Section 5 states the most gen-

their usual Church enco dings in a typ e-correct

eral instantiation problem and presents an algorithm to

way.

solve it. Section 6 presents a typ e inference algorithm.

Section 7 concludes.

 By slightly mo difying these Church enco dings, we

can also express existentially or universally quan-

tied comp onenttyp es of records and data typ es,

2 The Typ e System

thereby subsuming the typ e systems of Perry,

Figure 1 presents the abstract syntax of our kernel lan-

Läufer and Odersky,Rémy, and Jones. The en-

guage, Exp:  . As in the Hindley/Milner system, we

co dings give us principal typ e prop erties and typ e

distinguish b etween typ es, which cannot contain quan-

inference algorithms for these systems for free .

tication over typ e variables, and typ e schemes, which

 Unlike the situation in the simply typ ed -calculus

can. Compared to Milner's language Exp there are two

[Mor68] or ML [Mil78], it is no longer p ossible to

extensions that can b e considered indep endently, but

reduce typ e inference to a simple Herbrand uni-

that are most useful in combination. One extension

cation problem. We need to consider instead

considers typ e annotations for formal arguments and

the problem of nding a most general substitution

expressions; the other considers typ e declarations.

that makes one typ e scheme an instance of an-

other. Weshow here that this problem is reducible

Typ e Scheme Annotations

to the problem of rst-order unication under a

mixed prex [Mil92], which is decidable. Decid-

Typ e scheme annotations can b e applied to formal ar-

ability holds b ecause we still admit only typ es

guments in -abstractions x: :e and to expressions

and not typ e schemes in the range of substitutions

e:  . Annotations with typ es are common in program-

 otherwise the problem would b e equivalentto

ming languages that build on the Hindley/Milner sys-

semi-unication, which is undecidable [KTU89].

tem. For instance,

 Unlike the situation in F ,we still maintain a

map = f: a ! b. xs: [a]. case xs of ...

2

stratication b etween typ es and typ e schemes. A

declares the argumenttyp es of function map in terms of

universally quantied variable can b e instantiated

twotyp e variables a and b. By generalizing over these

Variables x; y ; z

Typ e Constructors T

0 0

Expressions e = x j x:e j ee j let x = e in e Exp terms

j x: :e j e :  annotated terms

j T typ e injection

1

j T typ e pro jection

j newtyp e T ::: =  in e typ e declaration

1 n

Typ e variables ; ;

Typ es  = j  !  j T ::: 

1 2 1 n

Typ e schemes  =  j  !  j8 :

1 2

Figure 1: Abstract syntax.

0 0

`    `   

1 2

1 2

!   `   

0 0

`  !    ! 

1 2

1 2

0 0

` [= ]   `   

2

8  6 ftv   8

0 0

`8 :   `  8 :

Figure 2: Instance rules for typ e schemes.

 ` T :  ! T

;x :  ` x : 

Taut Pro j

1

;T :  ` T : 

` T : T  ! 

0

` e :  ` e :  `   

2

Gen  6 ftv Sub

0

` e : 8 : ` e : 

0 0

:x:  ` e :  ` e :  !  ` e : 

x

Lamb da Apply

0 0

` x:e :  !  ` ee : 

x

0

:x:  ` e :  ` e : 

x

Typ ed Typ edLamb da

0

` x: :e :  !  ` e :  :

x

0 0 0

;T: 8 : ! T ` e :  ` e :  :x:  ` e : 

T x x

Newtyp e Let

0 0 0

` let x = e in e :  ` newtyp e T =  in e : 

x T

Figure 3: Typing rules.

The typing rules, given in Figure 3, largely follow the typ e variables we then obtain the usual p olymorphic

Hindley/Milner system. The two main dierences are typ e scheme for map:

b oth motivated by the p ossible o ccurrence of quanti-

map: 8a.8b.a ! b ! [a] ! [b].

ers at all levels in a typ e scheme. First, it is necessary

What is new here is the ability to annotate with typ e

to consider typ e schemes instead of typ es in the con-

schemes instead of typ es. For instance, it is now p ossi-

clusion of eachtyping rule, since typ e schemes cannot

ble to write

always b e reconstructed using generalization at the out-

ermost level. Second, Hindley/Milner's elimination rule

f g: 8c.[c] ! Int = g ["hello"] + g [1,2].

for outermost quantiers is replaced by a more general

As a consequence, a typ e scheme maynow form part

subsumption rule, which takes into account the instance

of a larger typ e scheme. For instance, f's most general

relation  on typ e schemes.

typ e scheme would b e

Typ e annotations alone are sucient for expressing

p olymorphic function arguments. But one shortcoming

8c.[c] ! Int ! Int.

of this system remains: the resulting second-order p oly-

We therefore have to give up Hindley/Milner's restric-

morphic functions cannot b e arguments of p olymorphic

tion that quantiers may o ccur only at the outermost

functions themselves, since this would require an in-

level of a typ e scheme and havetoadmittyp e schemes

stantiation of a typ e variable to a typ e scheme. For

suchas !  .

1 2

instance, the following co de would not b e typ e-correct:

An immediate consequence is that wehave to rene

the generic instance relation [DM82]ifwewantto

map f [length, const 0].

get principal typ es for the system with annotations.

The problem is that the typ e variable a in map's typ e

Consider the function x:Int.[ ]. Twoderivable typ e

cannot b e instantiated to the typ e scheme 8c.[c]!Int.

schemes for this function are

We circumvent this problem by providing a wayto

8a.Int ! [a] and Int !8a.[a].

package a typ e scheme in an explicitly declared data

typ e.

None of these typ e schemes is a generic instance of the

other. Furthermore, there is no third typ e scheme that

has b oth of these typ e schemes as generic instances.

Typ e Declarations

But using the relation  dened in Figure 2, weget

Atyp e declaration newtyp e T ::: =  in e cor-

1 n Int !8a.[a] as the more general of b oth typ e schemes.

resp onds to a simple form of an algebraic data typ e

The relation  implements a form of for

declaration with a single unary constructor. Eachtyp e

typ e schemes. Rule 8 together with subsumption

T :::  thus intro duced is dierent from [ = ] .

is equivalent to the quantier elimination rule of the

1 n i i

The typ e constructor T may b e used anywhere, includ-

Hindley/Milner system. Rule 8 allows us to re-

ing in the typ e scheme  .We require that every typ e

quantify a typ e scheme. Functions over typ e schemes

constructor is declared at most once in a program this

are handled by the standard contravariance rule !.

is not enforced by the typing rules. We often use the

As usual, weidentify typ e schemes that are instances

shorthand or  for vectors of typ e variables or typ es.

of each other.

A similar declaration in Haskell would b e

The relation  is a subrelation of Mitchell's con-

tainment relation [Mit90]andhenceisvalidated byall

data T a ... a = T elemtyp e.

1 n

typ e inference mo dels. For typ e schemes that have

quantiers only at the outermost level,  is the in-

We generalize Haskell in that elemtyp e may b e an arbi-

verse of the generic instance relation given by Damas

trary typ e scheme instead of a typ e.

and Milner [DM82]. Wechanged the direction of 

The Haskell syntax ab ovemakes explicit our con-

sign to stay in line with Mitchell's containment relation,

vention that T doubles up as an injection function that

which corresp onds to the semantic intuition of subtyp-

maps values of the comp onenttyp e to values of typ e

ing as inclusion.

 .For every new typ e constructor T there is also a T

1

 has the following useful prop erties.

pro jection function T , whichisaninverse of the in-

jection T .Bycontrast, pro jection in Haskell is implicit

0

Prop osition2.1 Let  and  be typ e schemes and let

in the meaning of case expressions. Instead of Haskell's

0 0

b e a substitution. If `    then `    .

case t of T x  e

Prop osition2.2  is transitive.

wewould write

Proof Sketch: Assume that    and    .We

1 2 2 3

show    by an induction on the sum of the depths

1 3

1

letx=T tine.

of the pro of trees for    and    . Prop osi-

1 2 2 3

tion 2.1 is used for the case where the last rule in the With the help of typ e declarations we can nowcodeour

pro of of    is an application of rule 8. 2 problematic example as follows.

1 2

Abstract Typ es newtyp e ListFun = 8c.[c] ! Int

1

in let f g = let g' = ListFun g

We consider a set of global data typedeclarations

in g' ["hello"] + g' [1,2]

in map f [ListFun length, ListFun const 0].

data D = k  j ::: j k  1

1 1 n n

But much more is p ossible. For once, newtyp e declara-

Here D is a data typ e constructor, and k ; :::; k are

1 n

tions are sucient to express data typ es with general

value constructors. Conceptually, a data typ e construc-

pro ducts and sums by their usual Church enco dings,

tor is a sp ecial instance of a typ e constructor T , whereas

combined with explicit injection and pro jection op era-

value constructors k form a separate alphab et. As in

tions. For instance, the typ e of pairs with a constructor

[LO94]we adopt the convention that anytyp e variables

mkpair and selectors fst and snd would b e co ded as fol-

in one of the  that do not app ear in are existentially

i

lows.

quantied. By contrast, in ML or Haskell suchtyp e

variables would b e disallowed.

newtyp e Pair a b = 8c. a ! b ! c ! c

inletmkpairxy=Pair k.kxy

Example 3.1 The following declares a typ e of lists

1

in let fst p =Pair p x.y.x

with heterogeneous elements. Each element consists

1

in let snd p =Pair p x.y.y

of some value and a function that maps this value to

in ...

an integer key. The typ e of the value mayvary from

element to element.

Note that the Pair typ e expands into a typ e scheme, not

atyp e. Therefore, we could not apply the same tech-

data KeyList = KNil

nique in languages like ML or Haskell, which admit only

j KCons a, a ! Int, KeyList

typ es on the right hand sides of data typ e declarations.

A second example enco des the list typ e, using the

A function that nds the maximal key can then b e

List typ e constructor recursively.

written as follows:

newtyp e List a = 8b.b ! a ! List a ! b ! b

maxkey xs = case xs of

in let nil = List n.c.n

f KNil  minint

in let x xs = List n.c.c x xs

j KCons y, f , ys  f y `max` maxkey ys g

in ...

Slightly mo difying our treatment of lists in the last sec-

A case expression like

tion, this program is translated into Exp :  as follows.

case xs of f nil  e j cons y ys  e g

1 2

newtyp e KeyList =

would then b e co ded as

8b.b! 8a.a, a!Int, KeyList ! b ! b

1

in let KNil = KeyList

List xs e y.ys.e .

1 2

n.c: 8a.a, a!Int, KeyList ! b. n

Of course, in an actual we

in let KCons x xs = KeyList

would assume that pro duct and sum typ es are den-

n.c: 8a.a, a!Int, KeyList ! b. c x, xs

able directly, without the need for Church enco dings.

in let maxkey xs =

The existence of the enco dings ensures in this case that

1

the additional language constructs require no essential

KeyList xs

additions to the typ e system  after all, wecould

minint

typ echeckby enco ding rst and then using our kernel

y, f , ys.f y `max` maxkey ys

language. In the next section, we apply this program

Note that the implied existential quantier for the typ e

to some p olymorphic extensions of the Hindley/Milner

variable a in the denition of KeyList turns into a second

system.

rank universal quantier in KeyList's translation.

3 Extensions

For the general case we augment our kernel language

Exp:  with value constructors and case expressions.

In this section, we showhow some previous exten-

sions of Hindley/Milner with emb edded quantiers can

e ::= :::

b e expressed in our system. In particular, we deal

j k

with Läufer and Odersky's version of abstract typ es

j case e of fk x  e j ::: j k x  e g

1 1 1 n n n

[LO94] and with Jones's version of p olymorphic struc-

tures [Jon95]. A system equivalent in expressiveness

Let Exp : +9 b e the term-language thus dened. Given

to Rémy's [Rém94] can then b e obtained by combining

= ftv n for i = adatatyp e declaration 1, let

i i b oth extensions.

1; :::; n. Then the following typing rules are equivalent overloading to our typ e system [Jon92,OWW95]. In

to the treatment in [LO94]. symmetry with our treatmentofdatatyp es, wenow

adopt the convention that anytyp e variables in one of

AbsI ` k : 8 :8 : ! D i =1;:::;n

the  that do not app ear in are universal ly quantied.

i i i

i

Example 3.3 We dene a typ e for set ob jects that

00

` e : D 

contain as a eld a p olymorphic map function.

00

0

` k : 8 : ! D 

i i

i

i =1; :::; n

struct Set a = f elem :a! Bo ol,

0

AbsE : !  ` x :e : 8

i i i

i

union : Set a ! Set a,

ftv   \ = ;

i

map :a! b ! Set b g

` case e of fk x  e j :::j k x  e g : 

1 1 1 n n n

Note that the typ e variable b in map's signature do es

not app ear on the left-hand side of the denition, and

9

Let ` b e the relation that results from adding these

hence is considered to b e universally quantied. This

9

rules to those in Figure 3. Wenowgive an enco ding  

structure declaration could b e expressed in Exp:  as

of Exp :  +9 in Exp :  that preserves typability.For the

follows.

constructors and case expressions that corresp ond to a

data typ e declaration 1, we dene:

newtyp e Set a = 8c.8b.a ! Bo ol !

Set a ! Set a !

9

^

k = k i =1; :::; n

i

i a ! b ! Set b ! c

^

where each k is a new variable,

i

! c.

9

case e of fk x  e j ::: j k x  e g

1 1 1 n n n

More generally, let the term language Exp:  + 8 be

1 9 9 9

= D e x :e  ::: x :e :

1 n

1 n

obtained by adding structure expressions and selector

functions to Exp :  .

9

We extend   homomorphically to all other expres-

e ::= ::: jfl = e ; :::; l = e gjl sions. Finally,we add for every data typ e declaration

1 1 n n

of form 1 the global declarations b elow, where is a

Given a structure typ e declaration 2, we add the

fresh typ e variable.

following typing rules, where = ftv n i =

i i

1; :::; n.

= 8 :8 : !  ! ::: ! newtyp e D

1 1

8 : !  !

n n

PolyI ` l : 8 :S !8 : i =1;:::;n

i i i

^

: ! : : : : : in let k = x:D y : 8

1 1 i 1

0

y : 8 : ! :y x

n n n i

` e : 8 : i =1; :::; n

i i

i

0

i =1; :::; n

00

PolyE ` l : S  !8 : i =1; :::; n

i i

i

00

`fl = e ;:::;l = e g : S 

1 1 n n

Then wehave:

8

Let ` b e the relation that results from adding these

Prop osition3.2 For all typ otheses , terms e and

rules to those in Figure 3. To enco de Exp : +8 in Exp:  ,

typ e schemes  in Exp :  + 9,

dene for every data typ e of form 2:

9 9

` e :  , ` e : :

8

^

l  = l

i i

^

Proof: An easy comparison of typing derivations. 2

where each l is a new variable,

i

8

fl = e ;:::;l = e g

1 1 n n

8 8

= S k :k e ::: e 

1 n

Polymorphic Structures

8

Extend   homomorphically to all other expressions An analogous treatment lets us enco de structures with

and add for every declaration 2 the global declarations

p olymorphic elds in Exp :  . Consider a set of global

structuredeclarations

newtyp e S = 8 :8 :::8 : ! ::: !  !  !

1 n 1 n

1

^

= fl :  ; :::; l :  g 2 struct S

in let l = x:S x y ::::y :y 

1 1 n n

i 1 n i

Then the following prop osition is shown by a compari-

Here, S isatyp e constructor, and l ;:::;l are eld

1 n

son of typing derivations.

lab els. Tokeep the treatment simple, we assume that

every lab el l o ccurs in at most one structure typ e dec-

Prop osition3.4 For all typ otheses , terms e and

laration; hence structures do not have scop es of their

typ e schemes  in Exp :  + 8,

own. A more exible scheme, in which a lab el could b e

8 8

part of several structures, would b e obtained by adding ` e :  , ` e : :

Discussion. One shortcoming of the presented en- Denition. The -lifting of a typ e  consists of an n-

co dings is that the comp onenttyp es of data typ es and ary typ e abstraction  and typ es  ;:::; suchthat

1 n

structures can have only one layer of quantiers. The  :::  =  and  ; :::;  are maximal subterms

1 n 1 n

enco dings share this prop erty with the original prop os- of  that do not contain .We write in this case

als of Läufer and Odersky and Jones, but not with

lift  =; ;:::; :

1 n

Rémy's system. A more p owerful typ e system would



We arrange such that for every translated typ e 8 : 

admit arbitrary typ e schemes for the comp onents. This

the translation contains a global typ e declaration

would present no problems for data typ es, hence Rémy's

system could b e expressed by a straightforward combi-

newtyp e T ::: = 8 : !  ::: :

 1 n 1 n

nation of our enco dings for data typ es and structures.



where lift  =; :::.

But an analogous generalization would not work for

For simplicity,weavoid variable renamings by as-

structure typ es, since there the result of a selection

suming that all typ e variables in the F source are mu-

2

is captured in a typ e variable, and therefore needs to

tually distinct. The enco ding of F typ es is then given

2

haveatyp e without quantiers. Of course, it is p os-

by:

sible to re-quantify at the outermost level after the se-



lection. Data typ es suer a dierent shortcoming 

=

  

alb eit for a similar reason  in that each branchina

 !   =  ! 

1 2

1 2



case-expression needs to havea typ e without quanti-

8 :  = T  ::: 

 1 n

ers.



where lift  =; ; :::;  :

1 n

It is p ossible to lift b oth restrictions by considering

This enco ding is stable under substitutions, as is shown

pro duct and sum typ es in the kernel language, with 

in the following lemma.

ranging over

Lemma 4.1 For all F typ es  ; ,typ e variables ,

2 1 2

 ::=  j  !  j    j  +  j8 :

  

[ = ]  =[ = ] :

1 2

1 2

Alternatively, one can also work around the restrictions

Proof: By induction on the structure of  .Thecase

2

byinventing intermediate data and structure typ es for

0

 = 8 : relies on the observation that if

2

2

each level of quantication.

lift  =; ;:::; 

1 n

then

4 Enco ding F

2

lift  =;  ; :::;  ;

1 n

In this section we present a translation of the second

for any substitution that do es not involve . 2

order p olymorphic -calculus F into our typing disci-

2



We extend   pointwise to typ e environments, den-

pline. F is given by the typing rules b elow.

2

ing

 

fx :  g = fx :  g:

i i i

F

i

;x :  ` x : 

Taut

Wenow address the enco ding of F terms. Since this

2

enco ding dep ends on b oth a term and its typ e, whichin

F 0



;x :  ` M : 

turn dep ends on a typ e environment, we formulate  

!I

F 0

` x: :M :  ! 

as a mapping from F 's typing rules for typ e judgments

2

F

` M :  to a dierent set of typing rules for

   

F 0 F 0

typ e judgments ` M :  .We will then show

` M :  !  ` N : 



!E

in a second step that each ` rule is valid as a `

F

` MN: 

derivation in an augmented environment.



Rules Taut, !I and !E are mapp ed by  

F

 F

` M : 

to identical rules with ` instead of ` .For the

2

8I  6 ftv 

F

remaining two rules, we dene: `  :M : 8 :



lift  =; ; :::;  

1 n

F

` M : 8 :



2

6 ftv  

8E



F 0 0

8I =

` M [ ]:[ = ]

  

` N : 

 

` T x : :N :T  ::: 

  1 n

The crucial idea of the translation of F into our typ-

2

ing discipline is that a p olymorphic F typ e 8 : is

2



mapp ed to a data typ e T  :::  where the typ e

lift  =; ; :::;  

 1 n

1 n



 

constructor T is indexed byann-ary typ e abstraction



8E = ` N : T  ::: 

 1 n

 and ; ; :::;   is the -lifting of  's translation:

1

1 n

  0 0  

` T N h i :[  = ] 

0

2

In rule 8E, the typ e argument [ ] is translated to a Lemma 4.4 If x 6 fve then ;x :  ` e :  i



representative h i, which is a term with typ e  .The ` e :  .

mapping hi from F typ es to representatives is dened

2

F

Theorem 4.5 If ` M :  byanF derivation D

2

b elow.

  

then ;  ` M :  .

D

h i = x

Proof: By an induction on the structure of D . If the



h !  i = x:  :h i

1 2 2

1

last step in the pro of is an application of a Taut rule,

h8 : i = T x : :h i



the result follows immediately. If it is one of !I or



where lift  =;:::

!E, the result follows by a simple inductive step.

0

Assume now that the pro of consists of a derivation D

Denition. Given a typ e scheme  ,let

F

of ` M :  , followed by an application of rule

2

 = fx : j ftv g:



F

` M : 

2

8I  6 ftv:

F

Analogously for an F term M ,let

2

`  :M : 8 :

2

 = fx : j ftv M g:

M

 F  

0

By the induction hyp othesis, ;  ` M :  .

D

0

0 2

Let  = nfx : g. Assume rst that ftv M .

D

Finally, for an F derivation D with conclusion `

2

0

Then  contains a binding x : . By rule Lambda,

D

M :  ,letS b e the set of all p olymorphic typ es of

D

form 8 : o ccurring in the environmentortyp e part of

 0  

;  ` x : :M : !  : 3

atyping judgmentinD .Thenthetyp e environment

 is given by

D

2

On the other hand, if 6 ftvM , 3 follows from the

induction hyp othesis, rule Lamb da, and Lemma 4.4.

 =  [f T : 8 :8 : !   ! T

 0

D M  

Then by rule Gen, since is free in ;  ,

2

j98 :  S :lift  =; :::g:

D

 0  

;  ` x : :M : 8 : !  : 4

Informally,  contains a binding x : for every

D

0

Furthermore,  contains b oth  and the binding

free variable in  , and it contains for every p oly-

D

morphic typ e in the derivation D a corresp onding typ e

:8 : !   ! T : 5 T : 8

 

constructor T .  can b e pro duced byaExp :  con-

 D

text that consists of a series of typ e declarations of the

It follows by rules Taut, Sub that

form



;  ` T :8 : !    ! T : 6

D  

newtyp e T ::: = 8 : !  ::: ;

 1 n 1 n

It also follows from 4 and Lemma 4.4 that

followed by a series of -abstractions of the form x :

  

.

;  ` x : :M : 8 : !  : 7

D





Lemma 4.2  `h i :  .

 by assumption, the case then follows Since  = 



from 6, 7 and an application of App.

Proof: Directly from the denition of hi. 2

Assume nally that the pro of D consists of a deriva-

0 F

tion D of ` M :  ,followed by an application of

The following prop osition is shown by a straightfor-

rule

F

ward induction on ` derivations.

F

` M : 8 :

8E :

F 0 0

Prop osition4.3 Let D be a typing derivation in F ` M [ ]: [ = ]

2

F

with conclusion ` M :  . Then there exists a

  

0

By the induction hyp othesis, ;  ` M :8 :  ,

  

D

unique term M and a ` -Pro of with structure D



where 8 :  = T  , for some typ e constructor T

 

that concludes with



 =  and D contains the binding suchthat

   

;  ` M :  :

M

T : 8 :8 : !   ! T : 8

 



It remains to b e shown that each D derivation can b e

Then byTaut, Pro j and Sub:

completed to a valid Exp :  derivation. Toshow this,

  1

we need a standard prop ertyofExp:  , namely that

0

 !8 : !  : 9 ;  ` T : T

D 



typ e derivations are invariant under weakenings and

additions of hyp otheses. This is stated in the following

By rule App,

lemma, whichisshown by a straightforward induction

1

  

0

M : 8 : !  : 10 ` T ; 

on typing derivations.

D 

5 Finding Most General Then by rule Sub,

1

  0  0  

Instantiators

0

;  ` T M :  ! [  = ] : 11

D



0

Since   it follows with Lemma 4.4 that

In this section we study the problem of nding sub-

D D

stitutions that make one typ e scheme an instance of

1

  0  0  

;  ` T M :  ! [  = ] : 12

D



another.

Furthermore, since   , Lemma 4.2 with

D 

Lemma 4.4 implies that

Preliminaries: Substitutions and Uni-

 0 0 

ers. Atyp e variable substitution is an idemp otent

;  ` h i :  : 13

D

mapping from typ e variables to typ es that maps all but

Then by 12, 13 and rule App ,

a nite number of typ e variables to themselves. Let

 1  0 0  

dom =f j 6= g. Substitutions are extended ho-

;  ` T M h i :[  = ] : 14

D



momorphically to mappings on typ es and typ e schemes.

Finally with Lemma 4.1,

When applying a substitution toatyp e scheme  ,

 1  0 0 

we assume that the b ound variables in  are disjoint

;  ` T M h i :[ = ]  ; 15

D



from dom . This can always b e achieved by renam-

which proves the case. 2

ing b ound variables in  .

Let 1 b e the identity substitution and let [= ] be

Example 4.6 Consider the successor function on

the mapping idemp otent or not that replaces by

Church-numerals

 . Comp osition of substitutions  and is written

n

n^ =  :f : ! :x : :f x;

 .LetV b e a set of typ e variables. Then j is

V

the substitution that equals on all typ e variables in

which is given by:

V and that is the identity on all other typ e variables.

succ : 8 : !  ! !  !

Conversely, n is the substitution that equals except

V

8 : !  ! !

on V , where it is the identity.

Let U b e a nite set of typ e variables. Usually we

succ = m: 8 : !  ! ! :

use U for the universe of typ e variables that are of

 :f : ! :x: :



interest in the situation at hand. We dene  if

m[ ] f fx:

1 2

U



  j = j .We write  if 9:  .

1 U 2 U 1 U 2 1 2

U

The liftings of succ's argument and result typ e schemes

Note that this makes the more general substitution

with resp ect to their quantied typ e variables are:

the smaller element in the pre-order  . This choice,

U

which reverses the usual convention in treatments of

lift 8 : !  ! ! =  !  ! !

unication e.g. [LMM87], was made to stay in line

lift 8 : !  ! ! =  !  ! ! :

with the semantic notion of typ e instance.

Wethus need the following global typ e declarations:

We make  a partial order byidentifying substitu-

U

tions that are equal up to variable renaming, or equiv-

newtyp e S = 8 : !  !  ! !

alently,by dening  = i   and  .It

U U U

newtyp e T = 8 : !  !  ! ! :

follows from [LMM87][Theorem 7] that  is a com-

U

plete lower semi-lattice where least upp er b ounds, if

Translating the successor function results in

they exist, corresp ond to unications and greatest lower



succ = m: S:T x : :f : ! :

b ounds corresp ond to anti-unications.

1

x: :S mx f fx:

The Instantiation Algorithm. We address

Although S and T are identical and a single typ e dec-

here the following problem.

laration would b e sucient, the translation do es not

provide this simplication.

Instantiating Substitution. Given typ e

0

schemes  and  , nd the most general sub-

It mightseemthatthe F translation makes our

2

0

stitution = MGI    such that

previous enco dings of abstract typ es and p olymorphic

0

   , provided exists; return failure

structures sup eruous, since these can clearly b e ex-

otherwise.

pressed in F . However, unlike these previous en-

2

co dings, which had only lo cal transformation rules for

This problem can b e reduced to the unication un-

terms, the translation of F dep ends on the full typing

2

der a mixed prex problem [Mil92]. Unication under

derivation of an F program. It is therefore not clear

2

a mixed prex involves nding a substitution U that

how to use the translation for validating typing rules for

solves a system of equations

abstract typ es and p olymorphic structures in Exp:  ,as

Q ::: Q :s = t ^ :::^ s = t we did in the last section.

1 1 m m 1 1 n n

I I

  [ = ] ` 

I I

2 2

[T = ] `  T   6 ftv  [T = ] ` T    6 ftv 

I

2

` !   !  ; new 6 ftv ; 

1 2 1 2 1 2 1 2

I

  [ ! = ]n `   ! 

1 2 1 2

f ; g

1 2

I

2

`  !   ! ; new 6 ftv ; 

1 2 1 2 1 2 1 2

I

  [ ! = ]n  `  !  

1 2 1 2

f ; g

i 2

I 0 I 0

`    `    = t

1 1 2 2 1 2

1 2

I

!

I 0 0

`  !    ! 

1 2

1 2

I 0

`    i =1; :::; n = t ::: t

i i 1 n

i

I

T 

I 0 0

` T ; :::;   T;:::;

1 n

1 n

I

` [ = ]   new

I

8

I

n ` 8 :  

f g

I 0 0

`   [T ::: = ] T new f ::: g =ftv; 8 : 

1 n 1 n

I

8

I 0

`  8 :

Figure 4: Algorithm MGI.

where the Q are 98-quantiers and s and t are simply- The meta-variable  in the rst clause of this mapping is

i i i

typ ed -terms. We shall b e concerned here only with assumed to range over typ e schemes without quantiers

the simpler problem where s and t are rst-order at the outermost-level:

i i

terms, i.e. typ es. The domain of the substitution U

0

 ::=  j  !  :

are the existentially quantied variables in the prex

Q ::: Q . Let b e one suchvariable. Then

1 1 m m i

Step 2: Bring the resulting system into prex form by

U can refer to anyvariable with j  i, but not to

i j

applying the equations

anyvariable b ound further to the right than .

i

0 0

E^Q :E  = Q :E^E 

The reduction of the instantiation problem to a uni-

0 0

cation under a mixed prex problem pro ceeds in three

Q :E  ^E = Q :E^E 

steps.

left-to-right as often as necessary.

Step 1:. Decomp ose the instantiation problem to a

0

Step 3: Let E     b e the system resulting from

2

system of equations with quantier prexes by applying



Step 2. Then a unication under a mixed prex prob-

the mapping   dened b elow.

0

lem E     is obtained by existentially quantifying

  0

all free variables in E .

2

2

8 :   = 9 :   if 6 ftv 

0  0 

2

 8 :  = 8 :    if 6 ftv   0

E    =9ftvE :E

2 2

0 0  0  0 

 !    !   =     ^    

1 2 1 2

1 2 1 2

0



Prop osition5.1 `    i is a solution to the

 !    = 9 ; : = ! ^

1 2 1 2 1 2

0

  problem E    .

    ^   

1 1 2 2

where ; new.

1 2

A more direct approach, which combines the trans-

0 0 

   !   = 9 ; : = ! ^

formation to a unication under a mixed prex and

1 2 1 2

1 2

0  0 

the solution of this problem in a single algorithm, is

   ^    

1 2

1 2

shown in Figure 4. Algorithm, MGI is expressed as an

where ; new.

1 2

0  0

inference system whose clauses are of the form

    =  = 

I 0

`    :

Each derivation step takes as inputs twotyp e schemes 6 Typ e Reconstruction

0

 and  . It yields as output a substitution .Wewill

Figure 5 explains the typ e reconstruction algorithm.

show that is the most general substitution suchthat

0

Following [Rém89], it is expressed as an inference sys-

`    holds.

I

tem, with clauses of the form

The most interesting rule of the algorithm is 8 .

2

This rule has to enforce the side-condition  6 ftv 

W G

V; ` e :  and V; ` e : :

in the corresp onding instance rule, 8. It do es this

by replacing withaSkolem function T that has as

Each derivation step takes as input a typ e variable set

0

arguments all other typ e variables in  and 8 : .

V ,atyp othesis and an expression e. It yields as out-

This way,any substitution whichwould violate the

put a substitution and a typ e scheme  . Informally,

side-condition by instantiating some typ e variable to

G

whenever a clause V; ` e :  is derivable, then is

I

would lead to failure of an   rule in MGI due to a

the identityonV and ` e :  holds. Furthermore,

circular variable dep endence an o ccurs check .

W

whenever V; ` e :  is derivable, then  is the

Wenow state soundness and completeness of algo-

most general typ e scheme suchthat ` e :  holds.

rithm MGI. The pro ofs for this and the following the-

This will b e made precise in the theorems b elow.

orems pro ceed by standard inductions on derivations.

The purp ose of the set of variables V is to prevent

Pro ofs are omitted here; they will b e given in a forth-

the computed substitution from touching typ e variables

coming technical rep ort [OL95].

that o ccur free in annotations. For instance, given the

function declaration

0

Lemma 5.2 Substitution If `    then `  

0

 .

map = f: a ! b. xs: [a]. case xs of ...

0

Theorem 5.3 Let ; be typ e schemes, let be a

the b o dy of map would b e typ echecked under assump-

substitution and let U b e a nite set of typ e variables.

tions f: a ! b, xs: [a]. It is not OK to instantiate these

variables when typ echecking the b o dy of map. Suchan

I 0 0

Soundness If `    then dom  ftv ; 

instantiation is prevented by including a and b in V .

0

and `    .

The typ e reconstruction algorithm uses the auxil-

E 0 0

0

iary clause `    , whichstatesthat is obtained

Completeness If `    then there is a sub-

I 0

from  by instantiating generic typ e variables. The only

stitution   suchthat `    .

U

W W

derivation rule for this clause is 8Elim . All `

W

For typ e reconstruction we need a slightly dierent

clauses have a derivation that ends in a Taut and

W G

version of this algorithm that restricts the returned sub-

Gen rule. All other rules in Figure 5 havea `

stitution to b e the identityonsomegiven variable set

conclusion. Informally, this forces a complete general-

V . This algorithm is again given in logical form. For

ization of the result typ e scheme after each derivation

I

simplicity,we reuse the ` symb ol, writing

step.

The most complex rules in the reconstruction algo-

I 0

V; `    :

rithm have to do with function application. Tworules

are needed, dep ending on whether typ e reconstruction

The mo died algorithm is obtained from MGI by

for the function part of the application yields a function

skolemizing V , using the rule b elow.

typeoratyp e variable. In the rst case, the rule com-

putes a substitution instance of the result typ e scheme

I 0

T ; :::; T new  =[T = ] `   

1 n i i i=1;:::;n

of the function. In the second case, a fresh typ e vari-

1 I 0

f ; :::; g ;  `   

1 n

able is created to hold the function result typ e, which

corresp onds to what is done in Hindley/Milner typ e

0

Corollary 5.4 Let ; be typ e schemes, let U and V

reconstruction.

b e nite sets of typ e variables, and let b e a substitu-

tion.

Lemma 6.1 Substitution If ` e :  then `

e : .

I 0

Soundness If V; `    then dom 

0 0

ftv ; nV and `    .

Theorem 6.2 Let be a typ othesis, let e b e an expres-

0

sion, let  be a typ e scheme. Let V ftv \ ftve

Completeness If `    and j = 1 then

V

I

and U b e nite sets of typ e variables and let be a

there is a substitution   such that V; `

U

0

substitution.

   .

W

Soundness If V; ` e :  then dom 

Proof: Direct from Theorem 5.3 and the denition of

ftvnV [ ftve;   and ` e :  .

mo died MGI. 2

W E

8Elim ` 8 :  [ = ] new

W W

Taut V;1 ;x :   ` x : 

W

V;1 ;T :   ` T : 

G

V; ` e : 

W

Gen

W

V; j ` e : 8ftv  nftv :

ftv

W

V;  :x:  ` e :  new

x

W

Lamb da

G

V; ` x:e : ! 

x

W 0

V [ ftv   ;  :x:   ` e : 

x

G 0

V; ` x: :e :  ! 

x

W E

V; ` e :  `    ! 

1 1 2

W W 0 0 I 0

Apply V; ` e :  V; `    = t t

2 3 1 1 2 3

G 0

V; ` ee : 

2

W E

V; ` e :  `   new

1

W 0 0 I 0

V; ` e :  V; `   ! = t t

2 3 1 2 3

G 0

V; ` ee :

W 0 I 0

V [ ftv   ; ` e :  V [ ftv  ; `    = t

1 2 1 2

W

Typ ed

G

V; ` e :  :

W W 0 0

V; ` e :  V;  :x:   ` e :  = t

1 x 2 x 1 2

W

Let

G 0 0

V; ` let x = e in e : 

x

E 0

2

T :  `    ! T 

W

Pro j

G 1 0

V;1 ` T : T  ! 

00 00 00 W 0

 = 8 : ! T V [ ftv   ;  ;T:   ` e : 

T

W

Newtyp e

G 0

V; ` newtyp e T =  in e : 

T

Figure 5: Typ e reconstruction algorithm.

Completeness If ` e :  and j = 1 An extension along these lines should yield a system in

V [ftv e

0



which parametric p olymorphism is regarded as a sp e-

then there is a substitution   and a typ e

U

cial form of subtyping, whichwould lead to a closer

0 W 0 0 0

scheme  such that V;  ` e :  and     .

integration of the twotyping disciplines.

Corollary 6.3 Principal Typ es Let b e a closed ty-

p othesis. If ` e :  then there is a typ e scheme

Acknowledgments

0 W 0 0

   such that ;; 1 ` e :  and ` e :  .

We'd like to thank Mark Jones, Benjamin Pierce, Didier

Rémy and Phil Wadler for stimulating discussions. The

7 Conclusion

idea of lifting out maximal subterms of p olymorphic

typ es in the F enco ding is due to Didier Rémy. Thanks

2

Wehave presented a typ e system that generalizes sev-

also to Dilip Sequeira for helpful comments on an earlier

eral recent second-order p olymorphic extensions of the

version of the pap er.

Hindley/Milner system. The presented typ e system

stays rmly in the tradition of Hindley/Milner in that

References

all Hindley/Milner programs continue to b e typable

with the same typ es, and the essential theorems carry

[Aug94] L. Augustsson. Haskell B. user's manual version

over.

0.999.7, Octob er 1994. Distributed with the HBC

Tokeep the present treatment simple wehavekept

compiler.

the typ e system fairly small. When applied in a pro-

[BMS80] Ro d Burstall, David MacQueen, and Donald T.

gramming language, several extensions would b e p ossi-

Sanella. Hop e: An exp erimental applicative lan-

ble and mayb e even desirable. Wehave already dis-

guage. In ConferenceRecord of the 1980 LISP

cussed p olymorphic sum and pro duct typ e schemes. Conference, pages 136143, Redwo o d Estates,

California, August 1980. The LISP Company.

As another p ossible extension, it is straightforward to

add p olymorphic recursion [Myc84], whichisknown

[Bo e89] Hans-J. Bo ehm. Typ e inference in the presence of

typ e abstraction. In Proceedings of the SIGPLAN

to b e undecidable in the absence of typ e declarations

'89 ConferenceonProgramming Language De-

[Hen93, KTU93].

sign and Implementation, pages 192206. ACM,

Starting with Hop e [BMS80], many programming

ACM Press, June 1989.

languages have supp orted p olymorphic recursion when

[DM82] Luis Damas and Robin Milner. Principal typ e

explicit declarations are given for p olymorphically re-

schemes for functional programs. In Proc. 9th

cursive functions. Nevertheless, we are not aware of

ACM Symposium on Principles of Programming

a formal analysis of typ e reconstruction for these lan-

Languages,January 1982.

guages. Our system can b e extended to p olymorphic

[Fel90] Matthias Felleisen. On the expressivepower of

recursion by adding the typing rule b elow.

programming languages. In Neil D. Jones, ed-

itor, ESOP '90, European Symposium on Pro-

0 0

;x:  ` e :  ;x:  ` e : 

x x

gramming, pages 134151. Springer-Verlag, 1990.

Letrec

0 0

Lecture Notes in Computer Science 432.

` letrec x:  = e in e : 

[Gir71] J. Girard. Une extension de l'interpretation

The corresp onding clause for the typ e reconstruction

de Gödel a l'analyse, et son applicatio n a

l'eliminatio n des coupures dans l'analyse et la

algorithm is:

theorie des typ es. In 2nd Scandinavian Logic

Symp., pages 6392, 1971.

W 00

V [ ftv  ;  ;x:   ` e : 

1 x

I 00 [Hen93] Fritz Henglein. Typ e inference with p olymorphic

V [ ftv  ; `   

2

recursion. ACM Transactions on Programming

W

W 0 0

V [ ftv  ;  ;x:   ` e :  Letrec

3 x

Languages and Systems, 151:253289, April

1993.

= t t

1 2 3

0 0

[Jon92] Mark P. Jones. QualiedTypes: Theory and

V; ` letrec x:  = e in e : 

Practice. D.phil. thesis, Oxford University,

Septemb er 1992.

An extension of the soundness and completeness pro ofs

[Jon95] Mark P. Jones. From Hindley-Miln er typ es to

for typ e reconstruction is straightforward.

rst-class structures. In Proc. Haskel l Workshop,

As a more ambitious extension one could combine

La Jol la, pages 115136, June 1995. Yale Univer-

our system with subtyping. This is particularly intrigu-

sity Research Rep ort YALEU/DCS/RR-1075.

ing since we already have a subsumption rule, alb eit for

[KTU89] A. Kfoury, J. Tiuryn, and P. Urzyczyn. The

typ e schemes, not for typ es. Moreover, the instance re-

undecidabil ity of the semi-unication problem.

lationship on function typ e schemes uses the contravari-

Technical Rep ort BUCS-89-010, Boston Univer-

ance rule that is standard in subtyping systems. What

sity, Oct. 1989. also in Pro c. of Symp. on Theory

is still missing is a denition of subtyping for typ es.

of Computing, Baltimore, Maryland, May 1990.

[Per90] N. Perry. The Implementation of Practical Func- [KTU93] A.J. Kfoury, J. Tiuryn, and P. Urzyczyn. Typ e

tional Programming Languages. PhD thesis, reconstruction in the presence of p olymorphic

Imp erial College of Science, Technology, and recursion. ACM Transactions on Programming

Medicine, University of London, 1990. Languages and Systems, 151:290311, April

1993.

[Pfe88] Frank Pfenning. Partial p olymorphic typ e infer-

[LMM87] J. Lassez, M. Maher, and K. Marriott. Unica-

ence and higher-order unication. In Proceedings

tion revisited. In J. Minker, editor, Foundations

of the 1988 ACM Conference on Lisp and Func-

of Deductive Databases and Logic Programming.

tional Programming, pages 153163, July 1988.

Morgan Kauman, 1987.

[Rém89] Didier Rémy.Typ echecking records and variants

[LO94] Konstantin Läufer and Martin Odersky. Poly-

in a natural extension of ML. In Proc. 16th ACM

morphic typ e inference and abstract data typ es.

Symposium on Principles of Programming Lan-

ACM Transactions on Programming Languages

guages, 1989.

and Systems, 165:14111430, Septemb er 1994.

[Rém94] Didier Rémy. Programming ob jects with ML-

[LPar] John Launchbury and Simon Peyton Jones. State

ART, and extension to ML with abstract and

in Haskell. Lisp and Symbolic Computation,to

record typ es. In Proc. Theoretical Aspects of

app ear.

Computer Software, pages 321346, April 1994.

[McC84] N. McCracken. The typ echecking of programs

Springer LNCS 789.

with implicit typ e structure. In Gilles Kahn,

[Rey74] John C. Reynolds. Towards a theory of typ e

David B. MacQueen, and Gordon D. Plotkin, ed-

structure. In InternationalProgramming Sympo-

itors, Semantics of Data Types, pages 301315.

sium, pages 408425. Springer-Verlag, 1974. Lec-

Springer-Verlag, June 1984. Lecture Notes in

ture Notes in Computer Science 19.

Computer Science 173.

[Wel94] J.B. Wells. Typability and typ e checking in the

[Mil78] Robin Milner. A theory of typ e p olymorphis m in

second order -calculus are equivalent and unde-

programming. Journal of Computer and System

cidable. In Proc. 9th IEEE Symposium on Logic

Sciences, 17:348375, Dec 1978.

in Computer Science, pages 176185, July 1994.

[Mil92] Dale Miller. Unication under a mixed prex.

Journal of Symbolic Computation, 14:321358,

1992.

[Mit90] John C. Mitchell. Polymorphic typ e inference

and containment. In Gérard Huet, editor, Logi-

cal FoundationsofFunctional Programming, The

UT Year of Programming Series, chapter 8.

Addison-Wesley Publishing Company, Inc., 1990.

[Mor68] J. H. Morris. Lambda-Calculus Models of Pro-

gramming Languages. PhD thesis, Massachusetts

Institute of Technology, 1968. Technical Rep ort

MAC-TR-57.

[MP88] J. Mitchell and G. Plotkin. Abstract typ es have

existential typ es. ACM Trans. on Programming

Languages and Systems, 103:470502, 1988.

[MP93] M. Mauny and F. Pottier. An implementation

of Caml-Light with existential typ es. Technical

rep ort, INRIA, Octob er 1993. Distributed with

the Caml-Light system.

[Myc84] A. Mycroft. Polymorphic typ e schemes and re-

cursive denitions. In Proc. 6th Int. Symposium.

on Programming, LNCS 167, 1984.

[OG89] James Willi am O'To ole and David K. Giord.

Polymorphic typ e reconstruction. In Proceed-

ings of the ACM SIGPLAN ConferenceonPro-

gramming Language Design and Implementation,

pages 207217. ACM, ACM Press, June 1989.

[OL95] Martin Odersky and Konstantin Läufer. Typ e

reconstruction in the presence of typ e scheme an-

notations. Technical rep ort, University of Karl-

sruhe, 1995. forthcoming.

[OWW95] Martin Odersky, Philip Wadler, and Martin

Wehr. A second lo ok at overloading. In Proc.

ACM Conf. on and

Computer Architecture, pages 1351469, June 1995.