Polymorphic Typ e Assignment and CPS Conversion

(To app ear: ACM SIGPLAN Workshop on Continuations, San Francisco, June 1992)

 y

Rob ert Harp er Mark Lillibridge

Carnegie Mellon University

Pittsburgh, PA15213

April 10, 1992

Abstract

Meyer and Wand established that the typ e of a term in the simply typ ed -calculus may b e related in

a straightforward manner to the typ e of its call-by-valu e CPS transform. This typing prop ertymaybe

extended to Scheme-likecontinuation-passi ng primitives, from which the soundness of these extensions

follows. We study the extension of these results to the Damas-Milner p olymorphic typ e assignment

system under b oth the call-by-value and call-by-name interpretations. We obtain CPS transforms for

the call-by-value interpretation, provided that the p olymorphi c let is restricted to values, and for the

call-by-name interpretation with no restrictions. We prove that there is no call-by-value CPS transform

for the full Damas-Milner language that validates the Meyer-Wand typing prop erty and is equivalentto

the standard call-by-value transform up to -conversion.

1 Intro duction

In their study of the relationship b etween direct and continuation semantics for the simply typ ed -calculus

! !

( ), Meyer and Wand note that the typ e of a term in  may b e related in a simple and natural wayto

the typ e of its call-by-value continuation passing style (CPS) transform [8]. This result may b e extended

!

to the calculus that results from extending  with Scheme-like continuation-passing primitives callcc and

! !

throw ( + cont)[1, 3]. Since  under a call-by-value op erational semantics is \typ e safe" in the sense of

Milner [9, 2], and since the call-by-value CPS transform faithfully mimics the call-by-value semantics [12],

!

+ cont under a call-by-value op erational semantics is also typ e safe. it follows that 

In a subsequent study Duba, Harp er, and MacQueen studied the addition of callcc and throw to Stan-

!

dard ML [10]. The extension of the Meyer-Wand transform to  + cont establishes the soundness of the

monomorphicfragment of the language, but the soundness of the p olymorphic language with continuation-

passing primitives was left op en. It was subsequently proved by the authors [7] that the full p olymorphic

language is unsound when extended with callcc and throw. The source of this discrepancy may b e traced to

the interaction b etween the p olymorphic let construct and the typing rules for callcc. Several ad hoc metho ds

for restricting the language to recover soundness have b een prop osed [6, 14].

In this pap er we undertake a systematic study of the interaction b etween continuations and p olymorphism

by considering the typing prop erties of the CPS transform for b oth the call-by-value and call-by-name

variants of the Damas-Milner language [2] and its extension with continuation-passing primitives. We obtain

suitable extensions of the Meyer-Wand theorem for the call-by-value CPS transform, provided that the

p olymorphic let is restricted to values, and for the call-by-name transform, under no restrictions. Finally,we



This work was sp onsored by the Defense Advanced Research Pro jects Agency, CSTO, under the title \The Fox Pro ject:

Advanced Development of Systems Software", ARPA Order No. 8313, issued by ESD/AVS under Contract No. F19628{91{C{

0168.

y

Supp orted by a National Science Foundation Graduate Fellowship. 1

prove that there is no call-by-value CPS transform for the full Damas-Milner language that b oth satis es the

Meyer-Wand typing prop erty and is equivalent to the usual transform up to -conversion. In particular,

the standard call-by-value CPS transform fails to preservetypability.

2 Untyp ed Terms

The language of untyp ed terms is given by the following grammar:

e ::= x j x:e j e e j let x be e in e j callcc j throw

1 2 1 2

Here x ranges over a countably in nite set of variables. We include the let construct as a primitive b ecause

it is needed in the discussion of p olymorphic typ e assignment. callcc and throw are continuation-passing

primitives whose de nitions are derived from analogous constructs in Scheme [1] and Standard ML of New

Jersey [3].

We consider two CPS transforms for untyp ed terms, corresp onding to the call-by-value and call-by-name

op erational semantics [12]. Each CPS transform consists of a transformation jj for untyp ed terms and a

transformation jjjj for untyp ed values. Exactly what is considered a value dep ends on which op erational

1

semantics is b eing used. Under call-by-value, variables, -abstractions, and constants are considered values.

Under call-by-name, only -abstractions and constants are considered values. We shall use v as a meta-

variable for call-by-value values and w as a meta-variable for call-by-name values.

De nition 2.1 (Call-by-Value CPS Transform)

jv j = k :k jjv jj

cbv cbv

je e j = k :je j (x :je j (x :x x k ))

1 2 cbv 1 cbv 1 2 cbv 2 1 2

jlet x be e in e j = k :je j (x:je j k )

1 2 cbv 1 cbv 2 cbv

jjxjj = x

cbv

jjx:ejj = x:jej

cbv cbv

jjcallccjj = f :k :f k k

cbv

jjthrowjj = c:k :k (x:l :c x)

cbv

Lemma 2.2

0 0

1. jj [v=x]v jj =[jjv jj =x ] jjv jj .

cbv cbv cbv

2. j [v=x]e j =[jjv jj =x ] jej .

cbv cbv cbv

0

We shall also haveneedofavariant call-by-value CPS transform (cbv ) de ned on untyp ed terms sat-

isfying the restriction that all let expressions are of the form let x be v in e. I.e., the let-b ound expression is

required to b e a (call-by-value) value. Because of this restriction, a simpler rule can b e given for the let case:

0 0 0

jlet x be v in ej = k :let x be jjv jj in (jej k )

cbv cbv cbv

This simpler rule for let expressions is the only di erence b etween the two transforms.

0

Lemma 2.3 Let v and v be values obeying the restriction on let expressions and e be a term obeying the

restriction on let expressions. Then

0 0

0 0 0

. =x ] jjv jj =[jjv jj 1. jj [v=x]v jj

cbv cbv cbv

0 0 0

2. j [v=x]e j =[jjv jj =x ] jej .

cbv cbv cbv

1

Note that callcc and throw are considered to b e constants. 2

De nition 2.4 (Call-by-Name CPS Transform)

jw j = k :k jjw jj

cbn cbn

jxj = x

cbn

je e j = k :je j (x :x je j k )

1 2 cbn 1 cbn 1 1 2 cbn

jlet x be e in e j = k :let x be je j in (je j k )

1 2 cbn 1 cbn 2 cbn

jjx:ejj = x:jej

cbn cbn

0 0

jjcallccjj = f :k :f (f :f (l :l k ) k )

cbn

0 0 0 0

jjthrowjj = c:k :k (x:l :c (c :x (x :c x )))

cbn

Lemma 2.5

1. jj [e=x]w jj =[jej =x ] jjw jj .

cbn cbn cbn

0 0

2. j [e=x]e j =[jej =x ] je j .

cbn cbn cbn

The correctness of these transforms may either b e established by relating them to an indep endently-

de ned op erational semantics (as in [12, 4]), or else taken as the de nition of call-by-value and call-by-name

semantics.

3 Simple Typ e Assignment

In this section we review Meyer and Wand's typing theorem for the call-by-value CPS transform for the

!

simply-typ ed -calculus ( ), and present an analogous result for the call-by-name CPS transform.

!

De nition3.1( Typ es and Contexts)

ty pes  ::= b j  ! 

1 2

contexts ::= j;x:

Here b ranges overacountable set of base typ es. We assume that among the base typ es there is a distinguished

typ e , which will b e used in what follows to represent the \answer" typ e of a CPS transform.

!

De nition3.2( Typing Rules)

.x:(x) (var)

;x: .e : 

1 2

(x 62 dom()) (abs)

. x:e :  ! 

1 2

.e :  !  .e : 

1 2 2 2

(app)

.e e : 

1 2

.e :  ;x: .e : 

1 1 1 2

(mono-let)

. let x be e in e : 

1 2

!

The typ e system  + cont is de ned by adding the typ e expression  cont and the following typing rules

for the continuation-passing primitives:

. callcc :( cont !  ) !  (callcc)

0

. throw :  cont !  !  (throw) 3

!

De nition 3.3 (Call-by-Value Typ e Transform for  )

j j = (jj jj ! ) !

cbv cbv

jjbjj = b

cbv

jj ! jj = jj jj !j j

1 2 cbv 1 cbv 2 cbv

The typ e transform is extended to contexts by de ning jjjj (x)= jj(x)jj for each x 2 dom().

cbv cbv

Theorem 3.4 (Meyer-Wand)

! !

1. If  ` .v :  , then  `jjjj . jjv jj : jj jj .

cbv cbv cbv

! !

2. If  ` .e :  , then  `jjjj . jej : j j .

cbv cbv cbv

!

The call-by-value typ e transform is extended to  + cont by de ning jj cont jj = jj jj ! .Itis

cbv cbv

!

straightforward to verify that Theorem 3.4 extends to  + cont in this way[3].

! 2

De nition 3.5 (Call-by-Name Typ e Transform for  )

j j = (jj jj ! ) !

cbn cbn

jjbjj = b

cbn

jj ! jj = j j !j j

1 2 cbn 1 cbn 2 cbn

The typ e transform is extended to contexts by de ning jj (x)=j(x)j for each x 2 dom().

cbn cbn

Theorem 3.6

! !

1. If  ` .w :  , then  `jj . jjw jj : jj jj .

cbn cbn cbn

! !

2. If  ` .e :  , then  `jj . jej : j j .

cbn cbn cbn

!

The call-by-name CPS transform is extended to  + cont by de ning jj contjj = jj jj ! , just

cbn cbn

!

as for call-by-value. It is straightforward to verify that Theorem 3.6 extends to  + cont in this way.

4 Polymorphic Typ e Assignment

In this section we study the extension of the Meyer-Wand typing prop erty to Damas and Milner's p olymor-

phic typ e assignment system (DM).

The syntax of typ es and contexts in (DM) is de ned by the following grammar:

De nition4.1(DM Typ es and Contexts)

monoty pes  ::= t j b j  ! 

1 2

polytypes  ::=  j8t:

contexts ::= j;x:

Here t ranges over a countably in nite set of typ e variables. The typing rules of the Damas-Milner system

!

extend those of  as follows:

2

The term \call-by-nametyp e transform" is something of a misnomer since there exists a by-value CPS transform that

validates the by-name typing prop erty[5]. Nevertheless we stick with the suggestive, if somewhat misleading, terminology. 4

De nition 4.2 (Additional DM Typing Rules)

.e: 

(t 62 FTV ()) (gen)

.e : 8t:

.e: 8t:

(inst)

.e:[=t]

.e :  ;x: .e : 

1 1 1 2 2

(x 62 dom()) (poly-let)

. let x be e in e : 

1 2 2

The system DM + cont is de ned by adding the typ e expression  cont , as b efore, and adding the following

typing rules:

. callcc : 8t:(t cont ! t) ! t (callcc')

. throw : 8s:8t:s cont ! s ! t (throw')

Let  and  b e the p olytyp es assigned to callcc and throw, resp ectively.

callcc throw

4.1 Restricted Call-by-Value

Let DM denote the sub-system of DM obtained by restricting let expressions so that the b ound expression

is a call-by-value value. The Meyer-Wand typing theorem may b e extended to terms of DM , provided that

0

we use the variant call-by-value CPS transform (cbv ) given in Section 2.

De nition 4.3 (Call-by-Value Typ e Transform for DM )

j j = (jj jj ! ) !

cbv cbv

j8t: j = 8t:j j

cbv cbv

jjtjj = t

cbv

jjbjj = b

cbv

jj !  jj = jj jj !j j

1 2 cbv 1 cbv 2 cbv

jj8t: jj = 8t:jj jj

cbv cbv

This de nition extends the Meyer-Wand typ e transform to p olymorphic typ es. In the terminology of

Reynolds [13], p olymorphic instantiation is given a \trivial" interpretation in that no interesting computation

can o ccur as a result of the sp ecialization of a value of p olymorphic typ e. The de nition of j8t: j re ects

cbv

the fact that in DM there is no need of continuations whose domain is a p olymorphic typ e.

Lemma 4.4

1. jj[=t] jj =[jj jj =t] jj jj .

cbv cbv cbv

2. j[=t] j =[jj jj =t] j j .

cbv cbv cbv

Theorem 4.5

0 0

1. If DM ` .v :  , then DM `jjjj . jjv jj : jj jj .

cbv cbv cbv

0 0

2. If DM ` .e :  ,thenDM `jjjj . jej : j j .

cbv cbv cbv

The pro of hinges on the following observations. First, the de nitions of the transformations jj and

cbv

jjjj on p olytyp es are such that the gen and inst rules carry over to applications of the same rule.

cbv

0

, and hence Sp eci cally,if .e:  and t do es not o ccur free in , then t do es not o ccur free in jjjj

cbv

0 0

: 8t:j j is derivable by an application of gen and the induction hyp othesis. A similar . jej jjjj

cbv cbv cbv

argument suces for the value transform. Uses of inst are handled similarly. 5

Second, the restriction on let expressions in DM combined with the use of the variant transform ensure

that let's are carried over to let's, and hence that p olymorphic typing is preserved. Sp eci cally,if .

0 0

v :  and ;x: .e :  are b oth derivable, then by induction jjjj . jjv jj : jj jj and

1 1 1 2 2 cbv 1 cbv 1 cbv

0 0 0 0 0

jjjj ;x:jj jj . je j : j j are derivable, and hence jjjj .k:let x be jjv jj in je j k :

cbv 1 cbv 2 cbv 2 cbv cbv 1 cbv 2 cbv

j j is also derivable.

2 cbv

Theorem 4.5 extends to DM + cont by de ning jj cont jj = jj jj ! .We need only verify that

cbv cbv

0 0

jjcallccjj and jjthrowjj ,given in Section 2, havetyp es jj jj and jj jj , resp ectively.The

cbv cbv cbv cbv

callcc throw

soundness of DM + cont under call-by-value follows from the extended theorem. (Same pro of as for the

!

soundness of  + cont under call-by-value.)

4.2 Call-by-Name

Theorem 3.6 (the Meyer-Wand-liketyping theorem for call-by-name) can b e extended to the unrestricted

DM langauge.

De nition 4.6 (Call-by-Name Typ e Transform for DM)

j j = (jj jj ! ) !

cbn cbn

j8t: j = 8t:j j

cbn cbn

jjtjj = t

cbn

jjbjj = b

cbn

jj ! jj = j j !j j

1 2 cbn 1 cbn 2 cbn

jj8t: jj = 8t:jj jj

cbn cbn

Lemma 4.7

1. jj [=t] jj =[jj jj =t] jj jj .

cbn cbn cbn

2. j [=t] j =[jj jj =t] j j .

cbn cbn cbn

Theorem 4.8

1. If DM ` .w :  , then DM `jj . jjw jj : jj jj .

cbn cbn cbn

2. If DM ` .e :  ,thenDM `jj . jej : j j .

cbn cbn cbn

The pro of pro ceeds along similar lines to that of the call-by-value case. For example, if .e : 

1 1

and ;x: .e :  are derivable, then by induction so are jj . je j : j j and jj ;x:j j .

1 2 2 cbn 1 cbn 1 cbn cbn 1 cbn

je j : j j , and hence so is jj .k:let x be je j in je j k : j j , as required.

2 cbn 2 cbn cbn 1 cbn 2 cbn 2 cbn

Theorem 4.8 extends to DM + cont by de ning jj contjj = jj jj ! .Weneedonlyverify that

cbn cbn

jjcallccjj and jjthrowjj ,given in Section 2, havetyp es jj jj and jj jj , resp ectively.The

cbn cbn cbn cbn

callcc throw

soundness of DM + cont under call-by-name op erational semantics follows from the extended theorem in a

manner similar to that of the call-by-value case for DM + cont .

4.3 Unrestricted Call-by-Value

Having established suitable typing prop erties for the variant call-by-value transform for DM and the call-

by-name transform for full DM, it is natural to consider whether there is a call-by-value CPS transform for

0

full DM that satis es a Meyer-Wand-liketyping prop erty. Since cbv is only de ned on terms with restricted

let expressions, we can not simply extend Theorem 4.5 to full DM.

0

Let us consider attempting to extend Theorem 4.5 to full DM by using cbv instead of cbv as the transform.

Consider the induction step for the p olymorphic let case. By induction wehave

DM `jjjj . je j : j j

cbv 1 cbv 1 cbv

and

DM `jjjj ;x:jj jj . je j : j j :

cbv 1 cbv 2 cbv 2 cbv 6

We are to show that

DM `jjjj .k:je j (x:je j k ):j j :

cbv 1 cbv 2 cbv 2 cbv

Since the call-by-value interpretation of let requires that e be evaluated b efore e , the call-by-value CPS

1 2

transform of let x be e in e involves a continuation whose argumentmay, in general, b e of p olymorphic typ e.

1 2

To capture this wemust change the de nition of jj so that j j =(jj jj ! ) ! . But this takes

cbv cbv cbv

us b eyond the limits of the Damas-Milner typ e system since jj jj is, in general, a p olytyp e. We therefore

cbv

+

consider as target language the extension, DM ,ofDM , in which the distinction b etween monotyp es and

p olytyp es is dropp ed, leading to full p olymorphic typ e assignment[11]. The decidabilityoftyp e checking

+

for DM is unknown, but this is not imp ortant for our purp oses. We shall rely,however, on the fact that

+

the sub ject reduction prop erty holds for -reduction in DM [11].

With these changes to the typ e transformation and the asso ciated enrichment of the target typ e sys-

tem, the induction step for general let's works. However, p olymorphic generalization b ecomes problematic.

+

Sp eci cally,ifDM ` .e:  with t 62 FTV (), then by induction DM `jjjj . jej : j j ,and

cbv cbv cbv

+

t 62 FTV (jjjj ). We are to show DM `jjjj . jej : j8t: j , and there is no evidentway to pro ceed.

cbv cbv cbv

We can indeed showthat jej has typ e 8t:(jj jj ! ) ! , but this is not enough. In fact we shall prove

cbv

that anyvariant call-by-value CPS transform jej verifying the Meyer-Wand typing prop ertyforDM must

not b e -convertible to jej .

cbv

The argument pro ceeds byway of the extension of DM with continuation passing primitives. Under the

call-by-value evaluation strategy, DM + cont is unsound. Sp eci cally,we can nd a term e such that e has

atyp e  , but whose value, when executed, fails to havetyp e  .Inotherwords, evaluation fails to resp ect

3

typing. Assuming that wehavebasetyp es int and bool, and constants 0: int and true : bool, the following

term is well-typ ed with typ e bool in DM + cont but evaluates under call-by-value to 0:

e = let f b e callcc (k :x:throw ky:x)

0

in (x:y :y )(f 0) (f true )

Using the typing rules of DM + cont ,the let-b ound identi er f is assigned the typ e 8t:t!t, and hence maybe

used at typ es int !int and bool!bool in the b o dy. But the binding for f grabs the continuation asso ciated

with the b o dy of the let expression and saves it. Up on evaluation of f 0, the continuation is invoked and f is

e ectively re-b ound to a constant function returning 0. The b o dy is re-entered, f 0isevaluated once again

(without diculty), but then f true is evaluated, resulting in 0.

It follows that there is no call-by-value CPS transform for DM + cont that preserves typability.Con-

sequently,any call-by-value CPS transform for DM must b e of a somewhat di erent form than the usual

one.

Theorem 4.9 (No Call-by-Value CPS Transform) Thereisnocal l-by-value CPS transform jej for DM

that simultaneously satis es the fol lowing two conditions:

1. Equivalence: jej = jej .

 cbv

+

2. Typing: If DM ` .e:  ,then DM `jjjj . jej : j j .

cbv cbv

Pro of: Given such a transform we could form je j (where e is given ab ove) by regarding callcc and

0 0

throw as variables of p olytyp e  and  , resp ectively. By the typing prop erty this term has

callcc throw

typ e jboolj , under the assumption that callcc and throw havetyp es jj jj and jj jj ,re-

cbv cbv cbv

callcc throw

sp ectively. Consequently the substitution instance e =[jjcallccjj ; jjthrowjj =callcc ; throw ] je j has typ e

1 cbv cbv 0

jboolj =(bool ! ) ! . But the corresp onding substitution instance of je j is precisely the call-

cbv 0 cbv

by-value CPS transform of e , taking accountofcallcc and throw directly. Since -conversion is preserved

0

under substitution, wehaveby the equivalence prop ertythate is -convertible to je j .Now, weknow

1 0 cbv

that je j x:x evaluates under call-by-value to 0. Consequently, this expression's  (and hence ) normal

0 cbv

3

This argument can b e made without constants but at the cost of increased complexity. Constants of base typ e can easily

b e added to any of the transforms presented in this pap er byde ningjjcjj = c, c a constant. Constants of non-base typ e must

b e handled on a case-by-case basis. 7

form is 0. Therefore, wehavethate x:x is -reducible to 0. But this is a violation of the sub ject reduction

1

+

prop ertyofDM [11]since e x:x has typ e bool!

1

The conditions of Theorem 4.9 leave op en the p ossibility of either nding a variant call-by-value transform

that is not convertible to the standard one, or else varying the typ e transform in suchaway that a Meyer-

Wand-liketyping prop erty can b e proved, or b oth. Anyvarianttyp e transform must b e such that either

jjcallccjj or jjthrowjj fail to have the required typ es under this transform so as to preclude extension to

cbv cbv

DM + cont .Weknow of no suchvariants, but have no evidence that none exist.

4.4 Related Transforms

It seems worthwhile, however, to p oint out that there is a varianttyp e transform that \almost" works. This

transform is de ned by taking jj8t: jj = 8t:j j,and j j =(jj jj ! ) ! .Theintuition b ehind this choice

is to regard p olymorphic instantiation as a \serious" computation (in roughly the sense of Reynolds [13]).

This interpretation is arguably at variance with the usual semantics of ML p olymorphism since it admits

primitives that have non-trivial computational e ects when p olymorphically instantiated. Nevertheless, we

can use this typ e transform to extend the Meyer-Wand theorem to a variant call-by-value CPS transform for

DM and to a variant call-by-name CPS transform for DM,provided that we restrict attention to programs

of monomorphic typ e. It do es not provide a variant call-by-value CPS transform for full DM b ecause of the

way in which p olymorphic generalization is handled.

To make these observations precise, wesketch the de nitions of variant CPS transforms based on this

typ e interpretation. The main idea is to de ne the CPS transform by induction on typing derivations so

that the e ect of p olymorphic generalization and instantiation can b e prop erly handled. Wegive here only

the two most imp ortant clauses, those governing the rules gen and inst:

j .e : 8t: j = k :k jej; where

j .e:  j = jej

j .e :[=t] j = k :jej (x:x k ); where

j .e : 8t: j = jej

This de nition may b e extended to the other inference rules in suchawayastoimplement either a call-

by-name or call-by-value interpretation of application. However, the transform fails (in general) to agree

with the usual (call-by-value or call-by-name) ML semantics on terms of p olymorphic typ e. Sp eci cally,

the transformation of a gen rule applies the currentcontinuation to the susp ended computation of e.

If this continuation is not strict, then an expression that would ab ort in ML terminates normally after

transformation into CPS. For example, consider the principal typing derivation of the term hd nil in a

context assigning the obvious typ es to hd and nil. The resulting transform, when applied to x:0, will yield

answer 0, despite the fact that the usual ML semantics leads to ab orting in this case.

By restricting attention to programs of monomorphic typ e, wemay obtain a correct CPS transform

for DM (under call-by-value) and DM (under call-by-name). This is essentially b ecause in DM under

call-by-value there are no non-trivial p olymorphic computations, and b ecause in DM under call-by-name the

semantics is de ned by substitution. But the ab ove argumentshows that this transform is incorrect for DM

under call-by-value. Sp eci cally, it fails to correctly implement the usual ML semantics for expressions such

as let x b e hd nil in 0 (which, under the ab ove transformation yields result 0 rather than ab orting).

5 Conclusion

The Meyer-Wand typing theorem for the call-by-value CPS transform for the simply-typ ed -calculus es-

tablishes a simple and natural relationship b etween the typ e of a term and the typ e of its call-by-value CPS

transform. Meyer and Wand exploited this relationship in their pro of of the equivalence of the direct and

!

continuation semantics of  [8]. A minor extension of this result may b e used to establish the soundness

! !

of typing for  + cont , the extension of  with continuation-passing primitives [3], under call-by-value.

In this pap er wehave presented a systematic study of the extension of the Meyer-Wand theorem to the

Damas-Milner system of p olymorphic typ e assignment. Our main p ositive results are the extension of the 8

Meyer-Wand theorem to the call-by-value interpretation of a restricted form of p olymorphism, and to the

call-by-name interpretation of the unrestricted language. These results have as a consequence the soundness

(in the sense of Damas and Milner [2]) of these programming languages. Wehave also argued that there is

no \natural" call-by-value CPS transform for the unrestricted language, but this leaves op en the p ossibility

of nding a transformation that is radically di erentincharacter from the usual one.

Our investigation makes clear that there is a fundamental tension b etween implicit p olymorphism and the

by-value interpretation of let. In particular, we are able to provide a CPS transform for the full Damas-Milner

language that extends to continuation-passing primitives, but which is \not quite" equivalent to the usual

call-by-value semantics. This suggests that a language in which p olymorphic generalization and instantiation

are semantically signi cantwould b e well-b ehaved, and might b e a suitable alternative to ML-style implicit

p olymorphism. We plan to rep ort on this sub ject in a future pap er.

6 Acknowledgments

We are grateful to Olivier Danvy, Tim Grin, Mark Leone, and the referees for their helpful comments on

earlier drafts of this pap er.

References

[1] William Clinger, Daniel P.Friedman, and Mitchell Wand. A scheme for higher-level semantic algebra.

In Maurice Nivat and John C. Reynolds, editors, Algebraic Methods in Semantics, pages 237{250.

Cambridge University Press, Cambridge, 1985.

[2] Luis Damas and . Principal typ e schemes for functional programs. In Ninth ACM Sym-

posium on Principles of Programming Languages, pages 207{212, 1982.

[3] Bruce Duba, Rob ert Harp er, and David MacQueen. Typing rst-class continuations in ML. In Eigh-

teenth ACM Symposium on Principles of Programming Languages,January 1991.

[4] Matthias Felleisen, Daniel Friedman, Eugene Kohlb ecker, and Bruce Duba. Asyntactic theory of

sequential control. Theoretical , 52(3):205{237, 1987.

[5] Timothy Grin. Private communication., January 1992.

[6] Rob ert Harp er, Bruce Duba, and David MacQueen. Typing rst-class continuations in ML. Revised

and expanded version of [3], in preparation.

[7] Rob ert Harp er and Mark Lillibridge. Announcement on the types electronic forum., July 1991.

[8] Alb ert R. Meyer and Mitchell Wand. Continuation semantics in typ ed lamb da calculi (summary). In

Rohit Parikh, editor, Logics of Programs,volume 224 of Lecture Notes in Computer Science, pages

219{224. Springer-Verlag, 1985.

[9] Robin Milner. A theory of typ e p olymorphism in programming languages. Journal of Computer and

System Sciences, 17:348{375, 1978.

[10] Robin Milner, Mads Tofte, and Rob ert Harp er. The De nition of StandardML. MIT Press, 1990.

[11] John C. Mitchell. A typ e-inference approach to reduction prop erties and semantics of p olymorphic

expressions. In 1986 Symposium on LISP and Functional Programming, pages 308{319, August 1986.

[12] . Call-by-name, call-by-value, and the lamb da calculus. Theoretical Computer Science,

1:125{159, 1975.

[13] John C. Reynolds. De nitional interpreters for higher-order programming languages. In Conference

Record of the 25th National ACM Conference, pages 717{740, Boston, August 1972. ACM. 9

[14] Andrew K. Wright and Matthias Felleisen. A syntactic approachtotyp e soundness. Technical Rep ort

TR91{160, Department of Computer Science, Rice University, July 1991. 10