skip to main content
research-article

Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform

Published: 31 August 2009 Publication History

Abstract

We describe the implementation of first-class polymorphic delimited continuations in the programming language Scala. We use Scala's pluggable typing architecture to implement a simple type and effect system, which discriminates expressions with control effects from those without and accurately tracks answer type modification incurred by control effects. To tackle the problem of implementing first-class continuations under the adverse conditions brought upon by the Java VM, we employ a selective CPS transform, which is driven entirely by effect-annotated types and leaves pure code in direct style. Benchmarks indicate that this high-level approach performs competitively.

Supplementary Material

JPG File (implementingfirst-classpolymorphicdelimitedcontinuationsbya.jpg)
MP4 File (implementingfirst-classpolymorphicdelimitedcontinuationsbya.mp4)

References

[1]
Agha, Gul, and Carl Hewitt. 1987. Concurrent programming using actors. In Object-oriented concurrent programming, 37--53. MIT Press, Cambridge, MA, USA.
[2]
Appel, Andrew W. 1992. Compiling with continuations. Cambridge University Press, New York, NY, USA.
[3]
Appel, Andrew W., and Trevor Jim. 1989. Continuation-passing, closurepassing style. In Proc. POPL'89, 293--302.
[4]
Asai, Kenichi. 2007. On typing delimited continuations: Three new solutions to the printf problem. Tech. Rep. OCHA-IS 07-1, Department of Information Science, Ochanomizu University, Tokyo, Japan. Available from: http://pllab.is.ocha.ac.jp/~asai/papers/.
[5]
Asai, Kenichi, and Yukiyoshi Kameyama. 2007. Polymorphic delimited continuations. In Proc. APLAS'07, vol. 4807 of LNCS, 91--108.
[6]
Atkey, Robert. 2006. Parameterised notions of computation. In Proc. MSFP'06, 31--45. Electronic Workshops in Computing, British Computer Society.
[7]
Balat, Vincent, and Olivier Danvy. 1997. Strong normalization by run-time code generation. Tech. Rep. BRICS RS-97-43, Department of Computer Science, University of Aarhus, Denmark.
[8]
Biernacki, Dariusz, Olivier Danvy, and Chung-chieh Shan. 2006. On the static and dynamic extents of delimited continuations. Science of Computer Programming 60(3):274--297.
[9]
Clinger, William D., Anne H. Hartheimer, and Eric M. Ost. 1999. Implementation Strategies for First-Class Continuations. Higher-Order and Symbolic Computation 12(1):7--45.
[10]
Cooper, Gregory H., and Shriram Krishnamurthi. 2006. Embedding dynamic dataflow in a call-by-value language. In Proc. ESOP'06, 294--308.
[11]
Courtney, Antony, Henrik Nilsson, and John Peterson. 2003. The Yampa arcade. In Proc. ACM SIGPLAN workshop on Haskell, 7--18.
[12]
Danvy, Olivier. 1998. Functional unparsing. J. Funct. Program. 8(06):621--625.
[13]
Danvy, Olivier, and Andrzej Filinski. 1989. A Functional Abstraction of Typed Contexts. Tech. Rep., DIKU University of Copenhagen, Denmark.
[14]
---. 1990. Abstracting control. In Proc. LFP'90, 151--160.
[15]
---. 1992. Representing Control: A Study of the CPS Transformation. Mathematical Structures in Computer Science 2(4):361--391.
[16]
Danvy, Olivier, Kevin Millikin, and Lasse R. Nielsen. 2007. On one-pass CPS transformations. J. Funct. Program. 17(6):793--812.
[17]
Dragos, Iulian, Antonio Cunei, and Jan Vitek. 2007. Continuations in the Java Virtual Machine. In Proc. ICOOOLPS'07.
[18]
Dyvbig, R. Kent, Simon Peyton-Jones, and Amr Sabry. 2007. A monadic framework for delimited continuations. J. Funct. Program. 17(6):687--730.
[19]
Elliott, Conal, and Paul Hudak. 1997. Functional reactive animation. In Proc. ICFP'97.
[20]
Felleisen, Matthias. 1991. On the expressive power of programming languages. Science of Computer Programming 17(1-3):35--75.
[21]
Felleisen, Matthias, Mitch Wand, Daniel Friedman, and Bruce Duba. 1988. Abstract continuations: a mathematical semantics for handling full jumps. In Proc. LFP'88, 52--62.
[22]
Felleisen, Mattias. 1988. The theory and practice of first-class prompts. In Proc. POPL-88, 180--190.
[23]
Filinski, Andrzej. 1994. Representing monads. In Proc. POPL'94, 446--457.
[24]
---. 1999. Representing layered monads. In Proc. POPL'99, 175--188.
[25]
Flanagan, Cormac, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The essence of compiling with continuations. In Proc. PLDI'93, vol. 28(6), 237--247.
[26]
Fournet, Cedric, and Georges Gonthier. 1996. The reflexive CHAM and the join-calculus. In Proc. POPL'96, 372--385.
[27]
Gabriel, Richard P. 1991. The design of parallel programming languages. In Artificial intelligence and mathematical theory of computation: papers in honor of john mccarthy, 91--108. Academic Press Professional, San Diego, CA, USA.
[28]
Gasbichler, Martin, and Michael Sperber. 2002. Final shift for call/cc:: direct implementation of shift and reset. In Proc. ICFP'02, 271--282.
[29]
Haller, Philipp, and Martin Odersky. 2006. Event-based programming without inversion of control. In Proc. JMLC'06, vol. 4228 of LNCS, 4--22.
[30]
---. 2009. Scala actors: Unifying thread-based and event-based programming. Theor. Comput. Sci 410(2-3):202--220.
[31]
Kameyama, Yukiyoshi, and Takuo Yonezawa. 2008. Typed dynamic control operators for delimited continuations. In Proc. FLOPS'08, vol. 4989 of LNCS, 239--254.
[32]
Kiselyov, Oleg. 2005. How to remove a dynamic prompt: static and dynamic delimited continuation operators are equally expressible. Tech. Rep. TR611, Department of Computer Science, Indiana University.
[33]
---. 2007. Genuine shift/reset in haskell98. Announcement and explanations posted on the Haskell mailing list on 12/12/2007. Implementation available from: http://okmij.org/ftp/Haskell/ShiftResetGenuine.hs.
[34]
Kiselyov, Oleg, Chung-chieh Shan, and Amr Sabry. 2006. Delimited dynamic binding. In Proc. ICFP'06, 26--37.
[35]
Lea, Doug. 2000. A Java fork/join framework. In Proc. ACM Java Grande, 36--43.
[36]
Moors, Adriaan, Frank Piessens, and Martin Odersky. 2008. Generics of a higher kind. In Proc. OOPSLA'08, 423--438.
[37]
Nielsen, Anders Bach. 2008. Scala compiler phase and plug-in initialization. Available from: http://lampsvn.epfl.ch/svn-repos/scala/lamp-sip/compiler-phase-init/sip-00002.xhtml.
[38]
Nielsen, Lasse R. 2001. A selective CPS transformation. Tech. Rep. RS-01-30, BRICS, Department of Computer Science, Aarhus University.
[39]
Odersky, Martin. 2000. Functional Nets. In Proc. European Symposium on Programming Languages and Systems, 1--25.
[40]
Pettyjohn, Greg, John Clements, Joe Marshall, Shriram Krishnamurthi, and Matthias Felleisen. 2005. Continuations from generalized stack inspection. SIGPLAN Not. 40(9):216--227.
[41]
Rompf, Tiark. 2007. Design and implementation of a programming language for concurrent interactive systems. Master's thesis, Institute of Software Technology and Programming Languages, University of Lubeck, Germany. Available from: http://vodka.nachtlicht-media.de/docs.html.
[42]
Rose, John. 2008. JSR 292: Supporting dynamically typed languages on the Java platform. http://jcp.org/en/jsr/detail?id=292.
[43]
Shan, Chung-chieh. 2004. Shift to control. In Proc. ACM SIGPLAN workshop on Scheme and functional programming, 99--107.
[44]
---. 2007. A static simulation of dynamic delimited control. Higher-Order and Symbolic Computation 20(4):371--401.
[45]
Srinivasan, Sriram. 2006. A thread of one's own. In New horizons in compilers workshop, hipc, bangalore.
[46]
Srinivasan, Sriram, and Alan Mycroft. 2008. Kilim: Isolation-typed actors for Java. In Proc. ECOOP'08, 104--128.
[47]
Strachey, Christopher, and Christopher P.Wadsworth. 2000. Continuations: A mathematical semantics for handling full jumps. Higher-Order and Symbolic Computation 13(1):135--152.
[48]
Thielecke, Hayo. 2003. From control effects to typed continuation passing. In Proc. POPL'03, 139--149.

Cited By

View all
  • (2021)Kotlin coroutines: design and implementationProceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3486607.3486751(68-84)Online publication date: 20-Oct-2021
  • (2021)Reachability types: tracking aliasing and separation in higher-order functional programsProceedings of the ACM on Programming Languages10.1145/34855165:OOPSLA(1-32)Online publication date: 15-Oct-2021
  • (2020)Verifying Selective CPS Transformation for Shift and ResetTrends in Functional Programming10.1007/978-3-030-47147-7_3(38-57)Online publication date: 11-May-2020
  • Show More Cited By

Index Terms

  1. Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 44, Issue 9
    ICFP '09
    September 2009
    343 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/1631687
    Issue’s Table of Contents
    • cover image ACM Conferences
      ICFP '09: Proceedings of the 14th ACM SIGPLAN international conference on Functional programming
      August 2009
      364 pages
      ISBN:9781605583327
      DOI:10.1145/1596550
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 31 August 2009
    Published in SIGPLAN Volume 44, Issue 9

    Check for updates

    Author Tags

    1. control effects
    2. delimited continuations
    3. program transformation
    4. selective CPS transform

    Qualifiers

    • Research-article

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)94
    • Downloads (Last 6 weeks)6
    Reflects downloads up to 08 Mar 2025

    Other Metrics

    Citations

    Cited By

    View all
    • (2021)Kotlin coroutines: design and implementationProceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3486607.3486751(68-84)Online publication date: 20-Oct-2021
    • (2021)Reachability types: tracking aliasing and separation in higher-order functional programsProceedings of the ACM on Programming Languages10.1145/34855165:OOPSLA(1-32)Online publication date: 15-Oct-2021
    • (2020)Verifying Selective CPS Transformation for Shift and ResetTrends in Functional Programming10.1007/978-3-030-47147-7_3(38-57)Online publication date: 11-May-2020
    • (2019)Compiling with continuations, or without? whatever.Proceedings of the ACM on Programming Languages10.1145/33416433:ICFP(1-28)Online publication date: 26-Jul-2019
    • (2015)A Refactoring Library for Scala Compiler ExtensionsCompiler Construction10.1007/978-3-662-46663-6_2(31-48)Online publication date: 2015
    • (2015)Concurrent CilkRevised Selected Papers of the 28th International Workshop on Languages and Compilers for Parallel Computing - Volume 951910.1007/978-3-319-29778-1_5(73-90)Online publication date: 9-Sep-2015
    • (2014)Type-directed language extension for effectful computationsProceedings of the Fifth Annual Scala Workshop10.1145/2637647.2637648(35-43)Online publication date: 28-Jul-2014
    • (2014)Reflection-Based Heterogeneous Migration of ComputationsProceedings of the 2014 Brazilian Symposium on Computer Networks and Distributed Systems10.1109/SBRC.2014.27(223-230)Online publication date: 5-May-2014
    • (2012)A meta-scheduler for the par-monadACM SIGPLAN Notices10.1145/2398856.236456247:9(235-246)Online publication date: 9-Sep-2012
    • (2012)A meta-scheduler for the par-monadProceedings of the 17th ACM SIGPLAN international conference on Functional programming10.1145/2364527.2364562(235-246)Online publication date: 9-Sep-2012
    • Show More Cited By

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Figures

    Tables

    Media

    Share

    Share

    Share this Publication link

    Share on social media