on one-pass cps transformations

Upload: prettyhat

Post on 08-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 On One-Pass CPS Transformations

    1/24

    BRICSBasic Research in Computer Science

    On One-Pass CPS Transformations

    Olivier Danvy

    Kevin Millikin

    Lasse R. Nielsen

    BRICS Report Series RS-07-6

    ISSN 0909-0878 March 2007

    B

    RICSRS-07-6

    Danvyetal.:OnOne-PassCPSTransformations

  • 8/6/2019 On One-Pass CPS Transformations

    2/24

    Copyright c 2007, Olivier Danvy & Kevin Millikin & Lasse R.Nielsen.

    BRICS, Department of Computer Science

    University of Aarhus. All rights reserved.

    Reproduction of all or part of this work

    is permitted for educational or research use

    on condition that this copyright notice is

    included in any copy.

    See back inner page for a list of recent BRICS Report Series publications.

    Copies may be obtained by contacting:

    BRICS

    Department of Computer Science

    University of Aarhus

    IT-parken, Aabogade 34

    DK8200 Aarhus NDenmark

    Telephone: +45 8942 9300

    Telefax: +45 8942 5601

    Internet: [email protected]

    BRICS publications are in general accessible through the World Wide

    Web and anonymous FTP through these URLs:

    http://www.brics.dk

    ftp://ftp.brics.dkThis document in subdirectory RS/07/6/

  • 8/6/2019 On One-Pass CPS Transformations

    3/24

    On One-Pass CPS Transformations

    Olivier Danvy, Kevin Millikin, and Lasse R. Nielsen

    BRICS

    Department of Computer Science

    University of Aarhus

    Mar ch 21, 2007

    Abstract

    We bridge two distinct approaches to one-pass CPS transformations, i.e., CPS

    transformations that reduce administrative redexes at transformation time in-

    stead of in a post-processing p hase. On e ap proach is comp ositional and higher-

    order, and is ind ependently du e to App el, Danvy and Filinski, and Wand , build-

    ing on Plotkins seminal work. The other is non-comp ositional and based on a

    reduction semantics for the -calculus, and is due to Sabry and Felleisen. To re-

    late the two approaches, we use three tools: Reynoldss defunctionalization and

    its left inverse, refunctionalization; a special case of fold-unfold fusion due to

    Ohori and Sasano, fixed-point promotion; and an implementation technique for

    reduction semantics due to Danvy and Nielsen, refocusing.

    This w ork is d irectly app licable to transforming programs into mon adic normal

    form.

    Revised version of BRICS RS-02-3.

    Theoretical Pearl to appear in the Journal of Functional Programming.IT-parken, Aabogade 34, DK-8200 Aarhus N, Denmark.

    Email: , ,

    i

  • 8/6/2019 On One-Pass CPS Transformations

    4/24

    Contents

    1 Introduction 1

    2 Standard CPS transformation 2

    2.1 Fro m co nt ext -b ased t o h ig her-o rd er . . . . . . . . . . . . . . . . . . . . . . . . 2

    2.2 Fro m h ig her-o rd er t o co nt ext -b ased . . . . . . . . . . . . . . . . . . . . . . . . 6

    2.3 Su m mary an d con clu sion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    3 Tail-conscious CPS transformation 8

    3.1 Making a context-based CPS transformation tail-conscious . . . . . . . . . . . 8

    3.2 Making a higher-order CPS transformation tail-conscious . . . . . . . . . . . . 9

    4 Continuations first or continuations last? 9

    5 CPS transformation w ith generalized reduction 105.1 Gen er aliz ed red u ctio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    5.2 A d m in ist ra tiv e g en er aliz ed red u ct io n . . . . . . . . . . . . . . . . . . . . . . . 10

    6 Tail-conscious CPS transformation a la Fischer wi th administrative -reductions

    and generalized reduction 10

    7 Conclusions and issues 11

    A Fixed-point promotion 11

    B Fusion of refocus and the context-based CPS transformation 13

    ii

  • 8/6/2019 On One-Pass CPS Transformations

    5/24

  • 8/6/2019 On One-Pass CPS Transformations

    6/24

    This d efinition uses tw o au xiliary fun ctions that are defined over the structure of their first

    argument: D accumulates the spine context of an application, and D aux dispatches over thetop constructor of the context. D aux could easily be inlined , giving

    D (v, [ ]) = vD (v0, C[[ ] t1]) = D

    (t1, C[v0 [ ]])

    D (v1, C[v0 [ ]]) = (C, v0v1)D (t0 t1, C) = D

    (t0, C[[ ] t1])

    bu t w e prefer to keep it since as stated above, this defin ition is in d efun ctionalized form [14]:

    the contexts form the d ata typ e of a d efun ctionalized function and D aux forms its apply func-tion [19,55]. We will exploit this property in Section 2.2.

    Conversely, one can also define a total function P that plugs a term into a context (oragain, as occasionally worded in the literature, that fills th e hole of a context with a term,

    yielding another term). This P function is straighforwardly defined by structural induction

    over its first argument:P : Contexts Terms Terms

    P([ ], t) = tP(C[v0 [ ]], t1) = P(C, v0 t1)P(C[[ ] t1], t0) = P(C, t0 t1)

    In essence, and as envisioned by Sabry and Felleisen [60], the context-based CPS trans-

    formation d ecomp oses a source term into a context and a p otential redex, CPS transforms

    the p otential redex, plugs a fresh variable into the context, and iterates. It form s our starting

    point in Section 2.1. We then massage this context-based transformation until we obtain the

    usual higher-order one-pass CPS transformation. In Section 2.2, we start from this higher-

    order one-pass CPS transformation and we walk back to the context-based CPS transforma-

    tion.

    The rest of th e article builds on Section 2. In Section 3, we refine the CPS transforma-

    tion to make it tail-conscious, to avoid spurious administrative -redexes in the CPS coun-

    terpart of source tail calls. Section 4 compares and contrasts the two standard variants of

    continuation-pa ssing style, i.e., with continuations first or last. We review the ad ministra-

    tive -redu ctions enabled by each variant. Section 5 ad dresses generalized reduction and

    how to integrate it in both the context-based an d th e higher-ord er one-pass CPS transforma-

    tions. Finally, in Section 6, we p ut everything together and assemble a tail-conscious CPS

    transformation w ith ad ministrative -reductions and that integrates generalized reduction.

    The continu ations-first variant of the result is the CPS transformation d esigned by Sabry and

    Felleisen for reasoning abo ut progr ams in continu ation-passing style [60].

    Prerequisites: We assum e a basic familiarity w ith the -calculu s [4], with redu ction sem an-

    tics [21,26,27,72], and with the notion of one-pass CPS transformation [17,60]. We also make

    use of Reynold ss d efun ctionalization, i.e., the d ata-structure representation of h igher-order

    functions [19,55] and of its left inverse, refunctionalization [15].

    2 Standard CPS transformation

    2.1 From context-based to higher-order

    The followin g left-to-right, call-by-value CPS transformation repeated ly decompo ses a sourceterm into a context and the ap plication of a p air of values, CPS transforms th e app lication,

    2

  • 8/6/2019 On One-Pass CPS Transformations

    7/24

    and plugs a fresh variable into the context. This process continues until the source term is a

    value.

    D efini tion 1 (Implicit context-based CPS transformation)

    T : Terms Variables TermsT(v, k) = k (Vv)

    T(C[v0v1], k) = (Vv0) (Vv1) (C (C, k))

    V : Values ValuesVx = x

    Vx.t = x.k.T(t, k)where k is fresh

    C : Contexts Variables ValuesC (C, k) = w.T(C[w], k)

    where w is fresh

    The CPS t ransformation of a program t is k.T(t, k), where k is fresh.

    Implicit in Definition 1 are the decomposition of a non -value source expression into a con-

    text and a potential redex (on the left-hand side of the second clause of the definition ofT)and the plugging of an expression into a context (on the right-hand side of the d efinition of

    C). Here is an explicit version of this d efinition, using D an d Pas d efined in Section 1:

    Definition 2 (Explicit context-based CPS transformation)

    T : (Values + Contexts PotRedexes) Variables TermsT(v, k) = k (Vv)

    T((C, v0v1), k) = (Vv0) (Vv1) (C (C, k))

    V : Values ValuesVx = x

    Vx.t = x.k.T(D t, k)where k is fresh

    C : Contexts Variables ValuesC (C, k) = w.T(D (P(C, w)), k)

    wherew is fresh

    The CPS t ransformation of a program t is k.T(D t, k), where k is fresh.

    If they are imp lemented literally, d ecomp osition and plugging entail a time factor that

    is linear in the size of the source program, in the w orst case. Overall, the w orst-case time

    comp lexity of the CPS transformation is then qu ad ratic in the size of the source program [21],

    which is an overkill since D is always applied to the result ofP. (We w rite always sinceD t = D (P([ ], t)).)

    Danvy an d Nielsen [21, 48] have show n that th e comp osition of plugging an d decompo-

    sition can be fused into a refocus fun ction R that makes the resulting CPS transformationoperate in time linear in th e size of the sou rce progr amor m ore precisely, in o ne p ass. The

    essence of refocusing for a reduction semantics satisfying the unique decomposition prop-erty is captured in the following proposition:

    3

  • 8/6/2019 On One-Pass CPS Transformations

    8/24

    Proposition 1 (Danvy & Nielsen [14,21]) For any term t and contextC,D (P(C, t)) = D(t, C).

    In words: refocusing amounts to continuing the decomposition of the given term in thegiven context. Intuitively, R map s a term and a context into the next context and potentialredex, if there is any.

    The definition ofR is therefore a clone of that ofD . In p articular, it involves an auxiliaryfunction R and takes the form of two state-transition functions:

    R : Terms Contexts Values + Contexts PotRedexesR(v, C) = R (C, v)

    R(t0 t1, C) = R(t0, C[[ ] t1])

    R : Contexts Values Values + Contexts PotRedexesR ([ ], v) = v

    R (C[[ ] t1], v0) = R(t1, C[v0 [ ]])R (C[v0 [ ]], v1) = (C, v0v1)

    (Again, R could be inlined.)We take this one-pass CPS transformation as the starting point of our derivation:

    D efini tion 3 (Context-based CPS transformation, refocuse d)

    T1 : (Values + Contexts PotRedexes) Variables TermsT1 (v, k) = k (V1v)

    T1 ((C, v0 v1), k) = (V1v0) (V1v1) (C1 (C, k))

    V1 : Values ValuesV1 x = x

    V1 x.t = x.k.T1 (R(t, [ ]), k)where k is fresh

    C1 : Contexts Variables ValuesC1 (C, k) = w.T1 (R(w, C), k)

    wherew is fresh

    The CPS t ransformation of a program t is k.T1 (R(t, [ ]), k), where k is fresh.

    In Definition 2,D

    was always ap plied to the result ofP

    . Similarly, in Definition 3,T1

    is

    always app lied to the result ofR. Ohori and Sasano [49] have shown that the comp ositionof fun ctions su ch as T1 an d R can be fused by fixed-point prom otion into a fun ction RT2 insuch a w ay that for any term t, context C, and continuation identifier k,

    T1 (R(t, C), k) = RT2(t, C, k).

    We detail this fusion in Appendices A and B. The resulting fused CPS transformation reads

    as follows:

    4

  • 8/6/2019 On One-Pass CPS Transformations

    9/24

    D efini tion 4 (Context-based CPS transformation, fuse d)

    RT2 : Terms Contexts Variables TermsR

    T2(v, C, k) = R

    T2(C, v, k)

    RT2(t0 t1, C, k) = RT2(t0, C[[ ] t1], k)

    R T2 : Contexts Values Variables Terms

    R T2 ([ ], v, k) = k (V2v)

    R T2(C[[ ] t1], v0, k) = RT2(t1, C[v0 [ ]], k)

    R T2(C[v0 [ ]], v1, k) = (V2v0) (V2v1) (C2 (C, k))

    V2 : Values ValuesV2 x = x

    V2 x.t = x.k.RT2 (t, [ ], k)where k is fresh

    C2 : Contexts Variables ValuesC2 (C, k) = w.RT2 (w, C, k)

    where w is fresh

    The CPS t ransformation of a program t is k.RT2 (t, [ ], k), where k is fresh.

    Because th e contexts are solely consum ed by the ru les d efining R T2 , this CPS transfor-mation is in the image of Reynoldss defunctionalization. The contexts are a first-order rep-

    resentation of the function type Values Variables Terms with R T2 as the app ly fun ction.As the last step of the d erivation, let u s therefore refun ctionalize this CPS transformation.

    Under the assump tion that C is refunctionalized asC, and for any t an d k, we d efine

    RT3( C, t, k) to equal RT2(C, t, k), and w e write V3 an d C3 to denote the counterparts ofV2an d C2 over refunctionalized contexts. We introdu ce the infix operator @ for app lications,and we overline and @ for th e static abstractions an d app lications introdu ced by refunc-

    tionalization; we also write u for the corresponding static variables. Symmetrically, we un-

    derline and @for the dynamic abstractions and applications constructing the residual CPS

    program, and we write w for the corresponding dynamic variables.

    [ ] is refun ctionalized asu.k.k @(V3u),

    corresponding to the first rule ofR T2 ;

    ifC is refun ctionalized as C then C[v0 [ ]] is refun ctionalized as

    u1.k.(V3v0) @(V3u1) @(C3( C, k)),

    correspond ing to the third rule ofR T2 ; and

    ifC is refun ctionalized as C then C[[ ] t1] is refun ctionalized as

    u0.k.RT3(t1, u1.k.(V3u0) @(V3u1) @(C3(C, k)), k),

    corresponding to the second rule ofR T2

    .

    5

  • 8/6/2019 On One-Pass CPS Transformations

    10/24

    The interpretation of contexts previously performed by R T2 is now p erformed by static ap-plication.

    An improvement: instead ofRT3 that op erates on t, C, and k, we can instead apply the

    refun ctionalized contextC to th e continuation identifier k as soon as it is available. To this

    end, we define a function T3 operating on t and on u. C @u @k, so that RT3(t, C, k) =

    T3(t, u. C @u @k). The result is the follow ing h igher-order CPS transform ation:

    D efini tion 5 (Context-based CPS transformation, refun ctionaliz ed)

    T3 : Terms (Values Terms) Terms

    T3(v, ) = @vT3(t0 t1, ) = T3(t0, u0.T3(t1, u1.(V3u0) @(V3u1) @(C3 )))

    V3 : Values ValuesV3 x = x

    V3 x.t = x.k.T3(t, u.k @(V3u))where k is fresh

    C3 : (Values Terms) Values

    C3 = w. @wwherew is fresh

    The CPS t ransformation of a program t is k.T3(t, u.k @(V3u)), where k is fresh.

    This CPS transformation is very close to the usua l higher-order one-pass CPS transforma-

    tion. It is manifestly not compositional, witness the applications ofV3 to th e static variables

    u0, u1, and u. This non-compositionality is directly inherited from th e initial context-basedCPS transform ation, which is also non -comp ositional.

    The non-compositionality can be read off the types if we write DTerms an d DValues for

    the syn tactic dom ains of source direct-style expressions and values an d CTerms an d CValues

    for the syntactic domains of target CPS expressions and values. The types of T3, V3, and C3are then as follows:

    T3 : DTerms (DValues CTerms) CTermsV3 : DValues CValues

    C3 : (DValues CTerms) CValues

    We can easily m ake this CPS transformation comp ositional by app lying V prior to ap-plying instead of afterwards. The types of the resulting compositional functions T4 an d C4then read as follows:

    T4 : DTerms (CValues CTerms) CTermsC4 : (CValues CTerms) CValues

    The result is then the usual higher-order one-pass CPS transformation, which is our starting

    point in Section 2.2.

    2.2 From high er-order to context-based

    App el [2], Danv y an d Filinski [16, 17], and Wand [71] each discovered the following higher-order one-pass CPS transformation:

    6

  • 8/6/2019 On One-Pass CPS Transformations

    11/24

    D efini tion 6 (Hig her-order CPS transformation)

    T4 : DTerms (CValues CTerms) CTerms

    T4(v, ) = @V4vT4(t0 t1, ) = T4(t0, u0.T4(t1, u1.u0@u1@(C4 )))

    V4 : DValues CValuesV4 x = x

    V4 x.t = x.k.T4(t, u.k @u)where k is fresh

    C4 : (CValues CTerms) CValues

    C4 = w. @wwherew is fresh

    The CPS t ransformation of a program t is k.T4(t, u.k @u), where k is fresh.

    Let u s d efun ctionalize th is higher-order transformation. The type CValues CTerms is

    inhabited by instances of three -abstractions (the overlined ones in Definition 6). It therefore

    gives rise to a data type with three constructors (written below as in ML) and its associated

    apply function interpreting these constructors.

    The corresponding defunctionalized CPS transformation reads as follows:

    D efini tion 7 (High er-order CPS transformation, defu nction alized)

    datatype Fun = F0 of Variables

    | F1

    of Fun

    DTerms

    | F2 of Fun CValues

    apply5 : Fun CValues CTermsapply5(F0 k, u) = k @u

    apply5(F1 (f, t1), u0) = T5(t1, F2 (f, u0))apply

    5(F2 (f, u0), u1) = u0@u1@(C5 f)

    T5 : DTerms Fun CTermsT5(v, f) = apply5(f, V5v)

    T5(t0 t1, f) = T5(t0, F1 (f, t1))

    V5 : DValues CValuesV5 x = x

    V5 x.t = x.k.T5(t, F0 k)where k is fresh

    C5 : Fun CValuesC5 f = w.apply5(f, w)

    where w is fresh

    The CPS t ransformation of a program t is k.T5(t, F0 k), where k is fresh.

    We recognize the result as a refocused context-based CPS transformation w here the con-

    texts hold elements ofCValues instead of elements ofDValues. The data type Fun plays the

    7

  • 8/6/2019 On One-Pass CPS Transformations

    12/24

    role of the contexts (ind exing each emp ty context with a continuation id entifier), apply 5 plays

    the role ofR T2 , and T5 plays the role ofRT2 .Alternatively, we can defunctionalize the CPS transformation of Definition 6 so that the

    data type and the type of its apply function read as follows:2

    datatype Fun = F0 of Variables

    | F1 of Fun DTerms| F2 of Fun DValues

    apply : Fun DValues CTerms

    We then ob tain th e CPS transformation of Definition 4.

    2.3 Summary and conclusion

    We have bridg ed tw o app roaches to one-pass CPS transformations, one that is context-based

    and non-comp ositional, and the other that is higher-order and comp ositional. This bridgeis significant because even th ough they share the same goal, the two app roaches have been

    developed ind ependently and have always been reported separately in the literature.

    We have used three tools to bridge the two CPS transformations: refocusing, fixed-point

    promotion, and defunctionalization. Refocusing short-cuts p lugging and decomposition,

    and mad e it possible for the context-based CPS transformation to op erate in one p ass. Fixed-

    point promotion is a special case of fold/ unfold fusion, and made it possible to fuse the

    resulting CPS transformation with its refocus function.3 Defun ctionalization an d its left in-

    verse, refun ctionalization, are chan ges of representation between the higher-order wor ld and

    the first-order world , and they m ad e it possible to relate higher-ord er and context-based CPS

    transformations.

    3 Tail-cons cious CPS transformation

    The CPS transformations of Section 2 generate one -red ex for each sou rce tail-call. For

    examp le, they map a term such as x.f (g x) into the following one:

    k.k (x.k.g x (w.f w (w .k w )))

    In th is CPS term , the continu ation of th e (tail) call to f is w .k w .

    In contrast, a tail-conscious CPS transformation would yield the following -reduced

    term:

    k.k (x.k.g x (w.f w k))

    Tail-consciousness m atters for read ability and in CPS-based compilers.

    3.1 Making a context-based CPS transformation tail-consciou s

    The specification ofC in Definition 2 can be refined as follows to mak e it tail-conscious:

    C : Contexts Variables ValuesC ([ ], k) = kC (C, k) = w.T(C[w], k) ifC = [ ]

    where w is fresh

    2This choice in defin ing a data typ e is similar to the choice between m inimally free expressions and maxima lly

    free expressions in sup er-combina tor conversion [50, pag es 245247].3

    In anoth er context [7,8,14,21], fixed-poin t prom otion mak es it possible to transform a pre-abstract machineinto a staged abstract machine.

    8

  • 8/6/2019 On One-Pass CPS Transformations

    13/24

  • 8/6/2019 On One-Pass CPS Transformations

    14/24

    ar e value -reductions, i.e., that they do not alter the properties of CPS-transformed pro-

    gram s, namely simu lation, ind ifference, and translation [38,51] as well as termination.

    At any rate, the current agreement in th e continu ation comm un ity is that ad ministrative

    -reductions bring more trouble than benefits. In fact, for un curried CPS, neither flavorprovides any extra opp ortunity for ad ministrative -redu ction b eyond tail consciousness. In

    short, only tail-consciousness m atters, and it work s both for Plotkin and Fischer, uniformly.

    5 CPS transformation w ith generalized reduction

    5.1 Generalized reduction

    In h is PhD thesis [58,60], Sabry considered lift, a generalized reduction that is most easily

    d escribed using redu ction contexts [10]:

    C[(x.t0) t1] lift (x.C[t0]) t1

    A lift-redu ction in the direct-style world correspond s to an adm inistrative (i.e., over-

    lined) -reduction in the corresponding CPS program a la Fischer:

    ((k.x.t 0) @c) @v1 adm (x.t

    0[c/k]) @v

    1

    (t 0 is the CPS counterp art oft0, v1 is the CPS counterpart oft1, and c represents C.)

    Sim ilarly, a lift-redu ction in th e direct-style world correspond s to an ad ministrative gen-

    eralized -redu ction in the correspond ing CPS program a la Plotkin:

    ((x.k.t 0) @v1) @c adm (x.t

    0[c/k]) @v

    1

    5.2 Admi nistrative generalize d reduction

    Integrating lift into the CPS transformation is achieved by refining the following rule in

    Definition 2:

    T(C[v0v1], k) = (Vv0) (Vv1) (C (C, k))

    The idea is to enumerate the possible instances ofv0, i.e., whether it denotes a variable or a

    -abstraction:T(C[x v1], k) = x (Vv1) (C (C, k))

    T(C[(x.t0) v1], k) = (x.T(C[t0], k)) (Vv1)renaming x if it occurs free in C

    As in Section 2, the refined context-based CPS transformation can be refocused to oper-

    ate in one-pass and refunctionalized to be higher-order. Making it compositional, however,

    makes th e CPS transformation d ependently typed [22]. The steps are reversible, turning a

    one-pass higher-order CPS transformation with generalized reduction into a one-pass refo-

    cused context-based CPS transformation.

    6 Tail-conscious CPS transformation a la Fischer with administra-

    tive -reductions and generalized reduction

    Putting everything together, Definition 2 can be made tail-conscious and extended with ad-

    ministrative -redu ctions and generalized redu ction. The result, if it is a la Fischer, coincid es

    with Sabry and Felleisens compacting CPS transformation (Sabry & Felleisen, 1993, Defini-

    tion 5). It can be refocused to operate in one-pass and refunctionalized to be higher-order.

    But as in Section 5, making it compositional makes the CPS transformation dependentlytyp ed [22]. The derivation steps are reversible.

    10

  • 8/6/2019 On One-Pass CPS Transformations

    15/24

    7 Conclusions and issues

    We have connected two d istinct app roaches to a one-pass CPS transformation th at have been

    reported separately in the literature. One is higher-order an d comp ositional, stems from

    denotational semantics, and can be expressed d irectly as a fun ctional program. The other

    is rewriting-based and non-compositional, stems from reduction semantics, and requires

    an adaptation such as refocusing to operate in one pass. The connection between the two

    ap proaches redu ces their choice to a m atter of conven ience.

    While all textbook descriptions of the one-pass CPS transformation [2, 32, 53] account

    for tail-consciousness, none pays a particular attention to administrative -reductions and

    to generalized reduction. For example, the context-based CPS transformation of the second

    edition ofEssentials of Programming Languages [32] produces uncurried CPS programs a la

    Plotkin and correspon ds to th e content of Section 3.

    The derivation steps p resented in th e present article can be u sed for richer langu ages, i.e.,

    languages with literals, primitive operations, conditional expressions, block structure, and

    comp utationa l effects (state, control, etc.). They also directly ap ply to tran sforming p rogram s

    into monadic normal form [6,30,37,46].

    Acknowledgments: Thanks are due to Julia L. Lawall for comments and to an anonymous

    reviewer for pressing u s to spell out how T1 an d R are fused ; Ohori and Sasanos fixed-pointpromotion provides a particularly concise explanation for this fusion.

    This work is partly supported by the Danish Natural Science Research Council, Grant

    no. 21-03-0545.

    A Fixed-point promotion

    We outline Ohori and Sasanos fixed-point promotion algorithm [49] and illustrate it with a

    simple example.

    Fixed-point promotion fuses the composition f g of a strict function f and a recursivefunction g. As a simp le examp le, consider a function comp uting the run -length encoding of a

    list. Given a list of elements, this function segments it into a list of pairs of elemen ts and non -

    negative integers, replacing each longest sequence s of consecutive identical elements x in

    the given list with a pa ir (x, n) where n is the length ofs. For exam ple, it ma ps [W,W,B,B,B]

    into [(W, 2), (B, 3)].

    We make use of an auxiliary tail-recursive function next that traverses a segment and

    computes its length. Additionally, if the rest of the list is nonempty, it also returns its head

    and tail:

    next : List() Nat Nat (Unit+ List())next (x, nil, n) = (x, n, ())

    next (x,x :: xs, n) = if x = x then next(x,xs, n + 1) else (x, n, (x , xs))

    A second auxiliary function continue dispatches on the return value of next and continues

    encoding the tail of th e list if necessary:

    continue : Nat (Unit+ List()List( Nat)continue (x, n, ()) = (x, n) :: nil

    continue (x, n, (x , xs)) = (x, n) :: continue (next (x ,xs, 1))

    11

  • 8/6/2019 On One-Pass CPS Transformations

    16/24

    The run-length encoding of a list is then the composition ofcontinue an d next:

    encode : List()List( Nat)encode nil = nil

    encode (x :: xs) = continue (next (x,xs, 1))

    To fuse this comp osition, we w ill use fixed-point p romotion an d proceed according ly in four

    steps.

    The first step is to inline the application ofnext in the composition to expose its body to

    continue:

    (x, xs, n).continue (next (x,xs, n))

    = {inline next}(x, xs, n).continue (case (x, xs, n)

    of (x, nil, n) (x, n, ())

    | (x, x :: xs, n) if x = x

    then next (x,xs, n + 1)else (x, n, (x , xs)))

    The second step is to distribute th e ap plication ofcontinue to the inner tail positions in

    the body ofnext. There are three such inner expressions in tail positionthe first arm of the

    case expression and both arms of the if expression:

    = {distribute continu e to inner tail positions}(x, xs, n).case (x, xs, n)

    of (x, nil, n) continue (x, n, ())

    | (x, x :: xs, n) if x = x

    then continue (next (x,xs, n + 1))

    else continue (x, n, (x , xs))

    The third step is to simp lify by, e.g., inlining app lications of continue to known argu-

    ments:

    = {inline applications of continue}(x, xs, n).case (x, xs, n)

    of (x, nil, n) (x, n) :: nil

    | (x, x :: xs, n) if x = x

    then continue (next (x,xs, n + 1))

    else (x, n) :: continue (next (x ,xs, 1))

    The fourth and final step is to use this abstraction to define a new recursive function

    nextc equal to continuenext, and to u se it to replace remaining occur rences ofcontinuenext.The auxiliary functions next an d continue are no longer needed, and the fused run-length

    encoding function reads as follows:

    nextc : List() Nat List( Nat)nextc (x, nil, n) = (x, n) :: nil

    nextc (x,x :: xs, n) = if x = x

    then nextc (x,xs, n + 1)

    else (x, n) :: nextc (x,xs, 1)

    encode : List() List( Nat)

    encode nil = nilencode (x :: xs) = nextc (x,xs, 1)

    12

  • 8/6/2019 On One-Pass CPS Transformations

    17/24

    In an actual implementation, the first parameter of next a n d o f nextc would be lambda-

    dropped [23].

    B Fusi on of refo cus and the context-based CPS transformation

    We now calculate the d efinition ofRT2 , wh ich is the fusion of th e refocus function R and thecontext-based CPS transformation T1 from Section 2.1. We work with a version ofR wherethe au xiliary fun ction R is inlined :

    R : Terms Contexts Values + Contexts PotRedexesR(v, [ ]) = v

    R(v0, C[[ ] t1 ]) = R(t1, C[v0 [ ]])R(v1, C[v0 [ ]]) = (C, v0v1)

    R(t0 t1, C) = R(t0, C[[ ] t1])

    We follow the same steps as in Appendix A (as specified for multiargument uncurried func-

    tions [49]), starting w ith th e comp osition ofT1 an d R:

    (t,C,k).T1 (R(t, C), k)= {inlineR}

    (t,C,k).T1(case (t, C)of (v, [ ]) v

    | (v0, C[[ ] t1]) R(t1, C[v0 [ ]])

    | (v1, C[v0 [ ]]) (C, v0v1)

    | (t0 t1, C) R(t0, C[[ ] t1]), k)

    = {distribute T1 (, k) to inner tail positions}(t,C,k).case (t, C)

    of (v, [ ]) T1 (v, k)

    | (v0, C[[ ] t1]) T1 (R(t1, C[v0 [ ]]), k)| (v1, C[v0 [ ]]) T1 ((C, v0v1), k)| (t0 t1, C) T1 (R(t0, C[[ ] t1]), k)

    = {inline t wo applications ofT1}(t,C,k).case (t, C)

    of (v, [ ]) k (V1v)| (v0, C[[ ] t1]) T1 (R(t1, C[v0 [ ]]), k)| (v1, C[v0 [ ]]) (V1v0) (V1v1) (C1 (C, k))

    | (t0 t1, C) T1 (R(t0, C[[ ] t1]), k)

    We then create a new recursive function RT2 to use in place of the composition ofT1 an d R(we renam e V1 to V2 an d C1 to C2, just as in Section 2.1):

    RT2 : Terms Contexts Variables TermsRT2 (v, [ ], k) = k (V2v)

    RT2(v0, C[[ ] t1], k) = RT2(t1, C[v0 [ ]], k)RT2(v1, C[v0 [ ]], k) = (V2v0) (V2v1) (C2 (C, k))

    RT2(t0 t1, C, k) = RT2(t0, C[[ ] t1], k)

    Inlining the auxiliary function R T2 in the d efinition ofRT2 from Section 2.1 yields this defi-

    nition.

    13

  • 8/6/2019 On One-Pass CPS Transformations

    18/24

    References

    [1] Lloyd Allison. A Practical Introduction to Denotational Semantics. Cambridge University

    Press, 1986.

    [2] Andrew W. Appel. Compiling with Continuations. Cambridge University Press, New

    York, 1992.

    [3] And rew W. Appel and Trevor Jim. Continuation-passing, closure-passing style. In

    Michael J. ODonnell and Stuart Feldman, editors, Proceedings of the Sixteenth Annual

    ACM Symposium on Principles of Programming Languages, pages 293302, Austin, Texas,

    January 1989. ACM Press.

    [4] Hen k Barend regt. The Lambda Calculus: Its Syntax and Semantics, volume 103 ofStudies

    in Logic and the Foundation of Mathematics. Nor th-Holland , revised ed ition, 1984.

    [5] Gilles Barthe, John Hatcliff, and Mor ten H eine Srensen. CPS translations and app li-cations: the cube and beyond. Higher-Order and Sy mbolic Comput ation, 12(2):125170,

    1999.

    [6] Nick Benton and And rew Kenned y. Monads, effects, and transformations. In Third

    International Workshop on Higher-Order Operational Techniques in Semantics, volume 26 of

    Electronic Notes in Theoretical Computer Science, pages 1931, Paris, France, September

    1999.

    [7] Magorzata Biernacka and O livier Danvy. A concrete framewor k for environment m a-

    chines. A CM Transactions on Comput ational Logic, 2006. To ap pear. Available as the

    technical report BRICS RS-06-3.

    [8] Magorzata Biernacka and Olivier Danv y. A syn tactic correspond ence between context-

    sensitive calculi a nd abstr act m achines. Technical Rep ort BRICS RS-06-18, DAIMI, De-

    partment of Computer Science, University of Aarhus, Aarhus, Denmark, December

    2006. To appear in Theoretical Computer Science (extended version).

    [9] Dariusz Biernacki, Olivier Dan vy, and Kevin Millikin. A d ynam ic continu ation-passing

    style for dy na m ic delimited continu ation s. Technical Report BRICS RS-06-15, DAIMI,

    Department of Computer Science, University of Aarhus, Aarhus, Denmark, October

    2006. Accepted for publication at TOPLAS.

    [10] Roel Bloo, Fairouz Kamareddine, and Rob Nederpelt. The Barendregt cube with defi-

    nitions and generalised reduction. Information and Computation, 126(2):123143, 1996.

    [11] Daniel Damian and Olivier Danv y. Syntactic accidents in p rogram an alysis: On the

    impact of the CPS transformation. Journal of Functional Programm ing, 13(5):867904,

    2003. A p reliminar y version w as presented at the 2000 ACM SIGPLAN Intern ational

    Conference on Functional Programming (ICFP 2000).

    [12] Olivier Danv y. Back to direct style. Science of Computer Programming, 22(3):183195,

    1994. A preliminary version was presented at the Fourth European Symp osium on

    Programming (ESOP 1992).

    [13] Olivier Danvy, ed itor. Proceedings of the Second A CM SIGPLAN Workshop on Continu-

    ations (CW97), Technical report BRICS NS-96-13, University of Aarhus, Paris, France,January 1997.

    14

  • 8/6/2019 On One-Pass CPS Transformations

    19/24

    [14] Olivier Danv y. From redu ction-based to red uction-free norm alization. In Sergio Antoy

    and Yoshih ito Toyam a, editors, Proceedings of t he Fourt h Int ernational W orkshop on R educ-

    tion Strategies in Rewriting and Programming (WRS04), volume 124(2) ofElectronic N otes

    in Theoretical Computer Science, p ages 79100, Aa chen, Germ an y, May 2004. Elsevier Sci-ence. Invited talk.

    [15] Olivier Danv y. Refunctionalization at w ork. In Prelimin ary proceedings of the 8th Interna-

    tional Conference on Mathematics of Program Construction (MPC 06), Kuressaare, Estonia,

    July 2006. Invited talk.

    [16] Olivier Danvy and And rzej Filinski. Abstracting control. In Mitchell Wand , editor,

    Proceedings of the 1990 ACM Conference on Lisp and Functional Programming, p ages 151

    160, N ice, France, June 1990. ACM Press.

    [17] Olivier Danvy and And rzej Filinski. Representing control, a stud y of the CPS transfor-

    mation. Mathematical Structures in Computer Science, 2(4):361391, 1992.

    [18] Olivier Dan vy and Julia L. Lawall. Back to d irect style II: First-class continuations. In

    William Clinger, editor, Proceedings of the 1992 A CM Conference on Lisp and Functional

    Programming, LISP Pointers, Vol. V, No. 1, pages 299310, San Francisco, California,

    Ju ne 1992. ACM Press.

    [19] Olivier Danvy and Lasse R. Nielsen. Defunctionalization at w ork. In Harald

    Sndergaard, editor, Proceedings of the Third International ACM SIGPLAN Conference on

    Principles and Practice of D eclarative Programm ing (PPDP01), pages 162174, Firenze,

    Italy, Septem ber 2001. ACM Press. Extend ed v ersion available as th e technical repor t

    BRICS RS-01-23.

    [20] Olivier Danvy and Lasse R. Nielsen. A first-order one-pass CPS transformation. Theo-

    retical Computer Science, 308(1-3):239257, 2003. A p relimina ry version w as p resented at

    the Fifth International Conference on Foundations of Software Science and Computa-

    tion Structures (FOSSACS 2002).

    [21] Olivier Danv y an d Lasse R. Nielsen. Refocusing in redu ction sem antics. Research Re-

    port BRICS RS-04-26, DAIMI, Department of Computer Science, University of Aarhus,

    Aarhus, Denmark, November 2004. A preliminary version appears in the informal pro-

    ceedings of the Second International Workshop on Rule-Based Programming (RULE

    2001), Electron ic N otes in Theoretical Com p u ter Science, Vol. 59.4.

    [22] Olivier Danv y an d Lasse R. Nielsen. CPS transformation of beta-redexes. InformationProcessing Letters, 94(5):217224, 2005. Extend ed v ersion a vailable as th e research rep ort

    BRICS RS-04-39.

    [23] Olivier Danvy and Ulrik P. Schultz. Lambda-dropping: Transforming recursive equa-

    tions into programs with block structure. Theoretical Computer Science, 248(1-2):243287,

    2000.

    [24] Olivier Dan vy and Carolyn L. Talcott, editors. Proceedings of the First ACM SIGPLAN

    Workshop on Continuations (CW92), Technical report STAN-CS-92-1426, Stanford Uni-

    versity, San Francisco, Californ ia, Jun e 1992.

    15

  • 8/6/2019 On One-Pass CPS Transformations

    20/24

    [25] Philippe de Groote. A CPS-translation of the -calculus. In Sophie Tison, editor, 19th

    Colloquium on Trees in A lgebra and Programm ing (CA A P94), nu mber 787 in Lecture N otes

    in Computer Science, pages 4758, Edinburgh, Scotland, April 1994. Springer-Verlag.

    [26] Matth ias Felleisen. The Calculi of -v-CS Conv ersion: A Synt actic Theory of Control and

    State in Imperative Higher-Order Programming Languages. PhD thesis, Computer Science

    Departm ent, Indiana University, Bloomington , Ind iana, Au gu st 1987.

    [27] Matthias Felleisen and Matthew Flatt. Programming langu ages and lambda calculi.

    Unpublished lecture notes. , 1989-2003.

    [28] An d rzej Filinski. An extensional CPS transform (preliminary repor t). In Sabry [59],

    pa ges 4146.

    [29] Michael J. Fischer. Lambd a-calculus schemata. LISP and Sym bolic Computation,

    6(3/ 4):259288, 1993. Available at . A preliminary version was presented at th e ACM Conference on Proving Asser-

    tions about Programs, SIGPLAN Notices, Vol. 7, No. 1, January 1972.

    [30] Corma c Flanagan , Amr Sabry, Bruce F. Duba, an d Matthias Felleisen. The essence of

    compiling w ith continuations. In David W. Wall, editor, Proceedings of the ACM SIG-

    PLAN 93 Conference on Programm ing Languages Design and Implementation, SIGPLAN

    Notices, Vol. 28, No 6, pages 237247, Albuquerque, New Mexico, June 1993. ACM

    Press.

    [31] Pascal Fradet and Daniel Le Metayer. Comp ilation of fun ctional langu ages by pro-

    gram transformation. ACM Transactions on Programming Languages and Systems, 13:21

    51, 1991.

    [32] Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes. Essentials of Program-

    min g Languages, second edition. The MIT Press, 2001.

    [33] Michael J. C. Gord on. The Denotational Description of Programming Languages. Springer-

    Verlag, 1979.

    [34] Timothy G. Griffin. A formulae-as-types notion of control. In Paul H ud ak, editor,

    Proceedings of the Seventeenth Annual ACM Symposium on Principles of Programming Lan-

    guages, pages 4758, San Francisco, California, January 1990. ACM Press.

    [35] Bob H arper and Mark Lillibridge. Polymorp hic type assignm ent and CPS conversion.LISP and Symbolic Computation, 6(3/ 4):361380, 1993.

    [36] John H atcliff. The Structure of Continuation-Passing Styles. PhD thesis, Department

    of Computing and Information Sciences, Kansas State University, Manhattan, Kansas,

    June 1994.

    [37] John Hatcliff and Olivier Danvy. A generic account of continuation-passing styles. In

    Hans-J. Boehm, editor, Proceedings of the Twenty-First Annual ACM Symposium on Prin-

    ciples of Programming Languages, p ages 458471, Por tland , Oregon, Janu ary 1994. ACM

    Press.

    [38] John Hatcliff and Olivier Danvy. Thunks and the -calculus. Journal of Functional Pro-gramming, 7(3):303319, 1997.

    16

  • 8/6/2019 On One-Pass CPS Transformations

    21/24

    [39] Richard A. Kelsey. Compilation by Program Transformation. PhD thesis, Comp uter Science

    Departm ent, Yale University, New Hav en, Conn ecticut, May 1989. Research Report 702.

    [40] David A. Kranz. OR BIT: A n Optimizin g Compiler for Scheme. PhD thesis, Computer Sci-

    ence Departm ent, Yale University, New Hav en, Con necticut, February 1988. Research

    Report 632.

    [41] Jakov Kucan. Retraction ap proach to CPS transform. Higher-Order and Symbolic Compu-

    tation, 11(2):145175, 1998.

    [42] Julia L. Law all. Continuation Introduction and Elimination in Higher-Order Programming

    Languages. PhD th esis, Compu ter Science Departm ent, Ind iana University, Blooming-

    ton, Indiana, July 1994.

    [43] Julia L. Lawall and Olivier Danvy. Separating stages in the continuation-passing style

    transformation. In Susan L. Graham, ed itor, Proceedings of the Twentieth Annual ACM

    Symposium on Principles of Programm ing Languages, pages 124136, Charleston, SouthCarolina, January 1993. ACM Press.

    [44] Albert R. Meyer and Mitchell Wand . Continu ation semantics in typ ed lambd a-calculi

    (sum mary). In Rohit Parikh, editor, Logics of Programs Proceedings, number 193 in

    Lecture N otes in Comp uter Science, p ages 219224, Brooklyn, New York, Jun e 1985.

    Springer-Verlag.

    [45] Kevin Millikin. A new app roach to one-pass transformations. In Marko van Eekelen,

    editor, Proceedings of the Sixt h Sy mposium on Trends in Functional Programming (T FP 2005),

    pages 252264, Tallinn, Estonia, September 2005. Institute of Cybernetics at Tallinn

    Techn ical University. Granted the b est stud ent-pap er award of TFP 2005.

    [46] Eugenio Moggi. Notions of compu tation and monads. Information and Computation,

    93:5592, 1991.

    [47] Lasse R. Nielsen. A selective CPS transformation. In Steph en Brookes and Michael

    Mislove, editors, Proceedings of the 17th Annual Conference on Mathematical Foundations

    of Programming Semantics, volume 45 ofElectronic Notes in Theoretical Computer Science,

    pages 201222, Aarhus, Denmark, May 2001. Elsevier Science Publishers.

    [48] Lasse R. Nielsen. A study of defunctionalization and continuation-passing sty le. PhD thesis,

    BRICS PhD School, University of Aarh u s, Aarhu s, Denm ark, Ju ly 2001. BRICS DS-01-7.

    [49] Atsushi Ohori and Isao Sasano. Lightweight fusion by fixed p oint p romotion. InMatthias Felleisen, editor, Proceedings of t he Thirty-Fourth A nnu al A CM Sym posium on

    Principles of Programming Langu ages, p age s 143154, New York , NY, USA, Jan u ary 2007.

    ACM Press.

    [50] Simon L. Peyton Jones. The Implementation of Functional Programm ing Languages. Prentice

    Hall International Series in Computer Science. Prentice-Hall International, 1987.

    [51] Gordon D. Plotkin. Call-by-nam e, call-by-value an d the -calculus. Theoretical Computer

    Science, 1:125159, 1975.

    [52] Gordon D. Plotkin. A structural approach to operational semantics. Technical Report

    FN-19, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Den-mark, September 1981.

    17

  • 8/6/2019 On One-Pass CPS Transformations

    22/24

    [53] Christian Queinnec. Lisp in Small Pieces. Cambridge University Press, Cambridge, Eng-

    land , 1996.

    [54] John Repp y. Optimizing n ested loops using local CPS conversion. Higher-Order and

    Symbolic Computation, 15(2/ 3):161180, 2002.

    [55] John C. Reynolds. Definitional interpreters for higher-order programming languages.

    In Proceedings of 25th ACM National Conference, pages 717740, Boston, Massachusetts,

    1972. Reprinted in Higher-Order and Symbolic Computation 11(4):363397, 1998, with

    a foreword [57].

    [56] John C. Reynolds. The discoveries of continu ations. Lisp and Symbolic Computation,

    6(3/ 4):233247, 1993.

    [57] John C. Reynolds. Defin itional interp reters revisited. Higher-Order and Symbolic Compu-

    tation, 11(4):355361, 1998.

    [58] Am r Sabry. The Formal Relationship between D irect and Cont inuation-Passing St yle Optim iz-

    ing Compilers: A Synt hesis of Two Paradigms. PhD thesis, Computer Science Department,

    Rice Un iversity, Hou ston , Texas, Au gu st 1994. Technical rep ort 94-242.

    [59] Amr Sabry, ed itor. Proceedings of the Third ACM SIGPLAN Workshop on Continuations

    (CW01), Technical report 545, Computer Science Department, Indiana University, Lon-

    don , England , Janu ary 2001.

    [60] Amr Sabry and Matthias Felleisen. Reasoning about programs in continuation-passing

    style. Lisp and Symbolic Computation, 6(3/ 4):289360, 1993.

    [61] Amr Sabry and Matthias Felleisen. Is continuation-passing useful for data flow analy-sis? In Vivek Sarkar, editor, Proceedings of the ACM SIGPLAN94 Conference on Program-

    ming Languages Design and Implementation, SIGPLAN Notices, Vol. 29, No 6, pages 112,

    Orlando, Florida, June 1994. ACM Press.

    [62] Amr Sabry an d Philip Wad ler. A reflection on call-by-value. ACM Transactions on Pro-

    gramming Languages and Systems, 19(6):916941, 1997. A p reliminar y ver sion w as p re-

    sented at the 1996 ACM SIGPLAN International Conference on Functional Program-

    ming (ICFP 1996).

    [63] Chu ng-chieh Shan. Shift to control. In Olin Shivers and Oscar Wad dell, editors, Proceed-

    ings of the 2004 ACM SIGPLAN Workshop on Scheme and Functional Programming, Techn i-

    cal report TR600, Computer Science Department, Indiana University, Snowbird, Utah,

    Sept em ber 2004.

    [64] Chung-chieh Shan. A static simulation of dynamic delimited control. Higher-Order and

    Symbolic Computation, 2007. Jou rn al ver sion o f [63]. To ap p ear.

    [65] Olin Shivers. Control-Flow Analysis of Higher-Order Languages or Taming Lambda. P h D

    thesis, School of Computer Science, Carnegie Mellon University, Pittsburgh, Pennsyl-

    vania, May 1991. Technical Report CMU-CS-91-145.

    [66] Gu y L. Steele. Rabb it: A comp iler for Schem e. M. Sc. thesis, Artificial Int elligen ce Lab-

    oratory, Massachu setts Institute of Technology, Cam bridge, Massachusetts, May 1978.

    Technical report AI-TR-474.

    18

  • 8/6/2019 On One-Pass CPS Transformations

    23/24

  • 8/6/2019 On One-Pass CPS Transformations

    24/24

    Recent BRICS Report Series Publications

    RS-07-6 Olivier Danvy, Kevin Millikin, and Lasse R. Nielsen. On One-

    Pass CPS Transformations. March 2007. ii+19 pp. Theoretical

    Pearl to appear in the Journal of Functional Programming. Re-

    vised version of BRICS RS-02-3.

    RS-07-5 Luca Aceto, Silvio Capobianco, and Anna Ingolfsdottir. On the

    Existence of a Finite Base for Complete Trace Equivalence over

    BPA with Interrupt. February 2007. 26 pp.

    RS-07-4 Kristian Stvring and Sren B. Lassen. A Complete, Co-

    Inductive Syntactic Theory of Sequential Control and State.

    February 2007. 36 pp. Appears in the proceedings of POPL

    2007, p. 161172.

    RS-07-3 Luca Aceto, Willem Jan Fokkink, and Anna Ingolfsdottir.

    Ready To Preorder: Get Your BCCSP Axiomatization for Free!

    February 2007. 37 pp.

    RS-07-2 Luca Aceto and Anna Ingolfsdottir. Characteristic Formulae:

    From Automata to Logic. January 2007. 18 pp.

    RS-07-1 Daniel Andersson. HIROIMONO is NP-complete. January

    2007. 8 pp.

    RS-06-19 Michael David Pedersen. Logics for The Applied Calculus.

    December 2006. viii+111 pp.

    RS-06-18 Magorzata Biernacka and Olivier Danvy. A Syntactic Corre-

    spondence between Context-Sensitive Calculi and Abstract Ma-

    chines. dec 2006. iii+39 pp. Extended version of an article to

    appear in TCS. Revised version of BRICS RS-05-22.

    RS-06-17 Olivier Danvy and Kevin Millikin. A Rational Deconstruction

    of Landins J Operator. December 2006. ii+37 pp. Revised ver-

    sion of BRICS RS-06-4. A preliminary version appears in theproceedings of IFL 2005, LNCS 4015:5573.

    RS-06-16 Anders Mller. Static Analysis for Event-Based XML Process-

    ing. October 2006. 16 pp.

    RS-06-15 Dariusz Biernacki, Olivier Danvy, and Kevin Millikin. A Dy-

    namic Continuation-Passing Style for Dynamic Delimited Con-

    tinuations. October 2006. ii+28 pp. Revised version of BRICS

    RS-05-16.