Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Using a Continuation Twice and Its Implications for the Expressive Power of call/cc

Using a Continuation Twice and Its Implications for the Expressive Power of call/cc

Ratings: (0)|Views: 3|Likes:
Published by Oliver Mayor

More info:

Published by: Oliver Mayor on Apr 27, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/27/2011

pdf

text

original

 
Higher-Order and Symbolic Computation, 12, 47–73 (1999)
c
1999 Kluwer Academic Publishers, Boston. Manufactured in The Netherlands.
Using a Continuation Twice and Its Implications forthe Expressive Power of 
call/cc
HAYO THIELECKE
*
ht@dcs.qmw.ac.uk 
 Department of Computer Science, Queen Mary and Westfield College, University of London
Abstract.
We study the implications for the expressive power of 
call/cc
of upward continuations, specificallythe idiom of using a continuation twice. Although such control effects were known to Landin and Reynolds whenthey invented
J
and
escape
, the forebears of 
call/cc
, they still act as a conceptual pitfall for some attempts toreason about continuations. We use this idiom to refute some recent conjectures about equivalences in a languagewith continuations, but no other effects. This shows that first-class continuations as given by
call/cc
havegreater expressive power than one would expect from
goto
or exits.
Keywords:
call/cc
, continuations, upward continuations, expressiveness, program equivalence.
1. Introduction
You can enter a room once, and yet leave it 
twice
.
(Peter Landin)A common informal explanation of continuations is the comparison with
forward 
goto
.This is in some sense a very apt simile: forward
goto
s obviously do not give rise to loops,and continuations, without some reflexive type, do not add this ability either — unlikebackward
goto
s, or
ml
exceptions with their general [21] type [19].Pushedtoofar,the
goto
analogycanbeharmful. Itisintuitivelyobviousthatifalljumpsare forward, one cannot jump to the same label twice. But it would be unsafe to concludethat, by analogy, one cannot invoke the same continuation twice.It was realised by Landin [17] (reprinted as a journal paper [18]) that his
J
(for jump)operator allows control quite unlike a forward
goto
.Wemayhowever, observethat, when
J
isadded, thefunction-producingfeatureamounts roughly to the possibility of jumping to a label after leaving the block inwhich it was introduced.Similarly, Reynolds writes about his
escape
:Forexample,itispossiblethattheevaluationofthebodyofanescapeexpressionmay not cause the application of the escape function, but may produce the escapefunction (or some function that may call the escape function) as its value. [24]In a more LISP-inspired jargon, “caus[ing] the application of the escape function” is calleda
downward 
use of the captured continuations, whereas “ the escape function (or some
*PartofthisworkwascarriedoutwhiletheauthorwasanEUHCMpostdocatINRIASophia-Antipolis,France;the author is currently funded from EPSRC grant GR/L54639.
 
48
THIELECKE
functionthatmaycalltheescapefunction)”
 producedasthevalue
isan
upward 
continuation[9].The first idiom of upward continuations that Reynolds mentions is
escape k ink
, or written with
call/cc
,
(call/cc (lambda (k) k))
. This implies a self-application of the continuation. With another self-application, one can define recursivefunctions, as in this obfuscated Scheme looping idiom [31]:
(define cycle-proc(lambda (proc)(let ((loop (call/cc (lambda (k) k))))(begin(proc)(loop loop)))))
In the present paper, we would like to study the expressive power of 
call/cc
in assimple a setting as possible, without the possibility of using it for recursion, so we will beconcerned with the second idiom mentioned in the quote: the argument of 
call/cc
may producesomefunctionthatmaycalltheescapefunctionasitsvalue
. Arguablythesimplestprocedure that has this kind of behaviour is the following procedure that calls the escapefunction (captured continuation):
(call/cc(lambda (k)(lambda (x)(k (lambda (y) x)))))
This idiom will be our canonical example of a control effect that is quite unlike what onewould expect from a forward
goto
.A consequence of the addition of computational effects to a language is that it becomesmore sensitive to details of the evaluation. Consider
((lambda (x) #f) (k #t))
.One cannot dispense with evaluating the argument, even if the result is thrown away. In thepresence of continuations, the context
(call/cc (lambda (k)
[]
))
can separate
((lambda (x) #f) (k #t))
and
#f
giving the answers
#t
and
#f
, respectively. This simple use of an exit is perhaps the mostelementary example of the discriminating power of 
call/cc
.But there are more subtle “non-equivalences” due to
call/cc
’s “defiance of the usualsubstitution rules” [17] — some of which were in fact conjectured to be equivalences.Furthermore, these non-equivalences can be shown using the control effects (upward con-tinuations) mentioned above.As far as formalisms for continuations are concerned, considerable progress has beenmade. Atanyrate,definitionalinterpretersor
cps
transformshavebeenaroundfordecades.Yet as we will see the conceptual subtleties remain when one reasons informally (as in:“continuationswithoutstatearetooweakaneffecttomeritinterest”),orpre-formally(whentrying to find plausible conjectures, before formally verifying them).Strachey and Wadsworth [32] put somewhat less emphasis than Landin and Reynolds onthe possibility of passing arguments to continuations. So in that setting, state in the form
 
THE EXPRESSIVE POWER OF
CALL/CC
49
of assignable labels is necessary for upward continuations. Furthermore, when upwardcontinuations are used in the literature, they are commonly used in conjunction with state.For instance, when “obtaining coroutines with continuations” [15, 23] the local controlstate of each coroutine stores its current continuation. This is done to enhance modular-ity, and should not be taken as an indication that state is somehow necessary for upwardcontinuations.
1.1. Related Work 
The examples that we present show that first-class continuations are good at distinguishing,ordiscriminatingbetween,
λ
-terms,andthusthattheyarea“powerful”effectinthesenseof Felleisen’s“expressivepower”[6],orBoudol’s“discriminatingpower”[3]. Landin[17,18]already used inequivalences to show the additional expressive power of 
J
(though the exactinequivalences used there are idiosyncrasies of 
J
and do not generalise to
call/cc
[36]).The particular idiom of using a continuation twice that we call
arg-fc
in the sequelwas already used as a counterexample to polymorphic type assignment [14]. Griffin [10]used a continuation twice for establishing the excluded middle in his formulae-as-typesinterpretation of control operators.The expressive power of 
call/cc
is discussed (and branded unreasonable) by Riecke[25, 20]; it was further analysed in Felleisen’s expressiveness framework [6]. In both cases,downward continuations are considered. Here, by contrast, we focus on upward continu-ations and control effects that are quite different from those of downward continuations.In Haynes’s paper on “logic continuations” [11], upward failure continuations are used toimplement nondeterminism (already mentioned by Reynolds [24]) by way of backtrack-ing. We found this connection to backtracking illuminating even for the highly idealised(stateless) setting of the present paper.
1.2. Outline
We recall the standard idealised language and the semantic setting that we will use, acall-by-value
λ
-calculus with
call/cc
, in Section 2. In Section 3, two functions thatuse their current continuation twice are discussed. Such an idiom forms the basis of thecounterexamples in the rest of the paper. Section 4 refutes Filinski’s [7] view of thetotal morphisms as effect-free, and as a corollary the “idempotency hypothesis for controleffects”, which was informally conjectured by Amr Sabry. In Section 5, we give furtherevidence for the expressive power of 
call/cc
by showing that two
λ
-terms that cannotbe distinguished in various extensions of “lazy” or weak call-by-name
λ
-calculus can beseparated with an analogue of the technique we had used in call-by-value. Section 6concludes and points towards further work.Areaderchieflyinterestedin
call/cc
aspartofSchemeorStandardMLofNewJerseymay wish to skim much of the formalism, focusing on Section 3 and the Scheme code inthe figures. Conversely, a more theoretically-minded reader could skim Section 3 and tracedefinitions and proofs from Section 2 onwards.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->