Skip to main content

Delimited Control in OCaml, Abstractly and Concretely: System Description

  • Conference paper
Functional and Logic Programming (FLOPS 2010)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 6009))

Included in the following conference series:

Abstract

We describe the first implementation of multi-prompt delimited control operators in OCaml that is direct in that it captures only the needed part of the control stack. The implementation is a library that requires no changes to the OCaml compiler or run-time, so it is perfectly compatible with existing OCaml source code and byte-code. The library has been in fruitful practical use for four years.

We present the library as an implementation of an abstract machine derived by elaborating the definitional machine. The abstract view lets us distill a minimalistic API , scAPI , sufficient for implementing multi-prompt delimited control. We argue that a language system that supports exception and stack-overflow handling supports scAPI . Our library illustrates how to use scAPI to implement multi-prompt delimited control in a typed language. The approach is general and can be used to add multi-prompt delimited control to other existing language systems.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Kiselyov, O.: Native delimited continuations in (byte-code) OCaml (2006), http://okmij.org/ftp/Computation/Continuations.html#caml-shift

  2. Kiselyov, O., Shan, C.-c., Sabry, A.: Delimited dynamic binding. In: ICFP, pp. 26–37 (2006)

    Google Scholar 

  3. Kiselyov, O., Shan, C.-c.: Embedded probabilistic programming. In: Taha, W.M. (ed.) Domain-Specific Languages. LNCS, vol. 5658, pp. 360–384. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  4. Kiselyov, O., Shan, C.-c.: Monolingual probabilistic programming using generalized coroutines. In: Uncertainty in Artificial Intelligence (2009)

    Google Scholar 

  5. Kiselyov, O.: Persistent delimited continuations for CGI programming with nested transactions. Continuation Fest 2008 (2008), http://okmij.org/ftp/Computation/Continuations.html#shift-cgi

  6. Kameyama, Y., Kiselyov, O., Shan, C.-c.: Shifting the stage: Staging with delimited control. In: PEPM, pp. 111–120 (2009)

    Google Scholar 

  7. Kiselyov, O., Shan, C.-c.: Lifted inference: Normalizing loops by evaluation. In: Proc. 2009 Workshop on Normalization by Evaluation, BRICS (2009)

    Google Scholar 

  8. Kiselyov, O.: Ask-by-need: On-demand evaluation with effects (2007), http://okmij.org/ftp/Computation/Continuations.html#ask-by-need

  9. Gunter, C.A., Rémy, D., Riecke, J.G.: A generalization of exceptions and control in ML-like languages. In: Functional Programming Languages and Computer Architecture, pp. 12–23 (1995)

    Google Scholar 

  10. Dybvig, R.K., Peyton Jones, S.L., Sabry, A.: A monadic framework for delimited continuations. J. Functional Progr. 17, 687–730 (2007)

    Google Scholar 

  11. Balat, V., Di Cosmo, R., Fiore, M.P.: Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums. In: POPL 2004, pp. 64–76 (2004)

    Google Scholar 

  12. Hieb, R., Dybvig, R.K., Bruggeman, C.: Representing control in the presence of first-class continuations. In: PLDI 1990, pp. 66–77 (1990)

    Google Scholar 

  13. Gunter, C.A., Rémy, D., Riecke, J.G.: Return types for functional continuations (1998), http://pauillac.inria.fr/~remy/work/cupto/

  14. Kiselyov, O.: Zipper in Scheme (2004), comp.lang.scheme, http://okmij.org/ftp/Scheme/zipper-in-scheme.txt

  15. Kiselyov, O.: Zipper as a delimited continuation. Message to the Haskell mailing list (2005), http://okmij.org/ftp/Haskell/Zipper1.lhs

  16. Felleisen, M.: The theory and practice of first-class prompts. In: POPL, pp. 180–190 (1988)

    Google Scholar 

  17. Leroy, X.: The ZINC experiment: An economical implementation of the ML language. Technical Report 117, INRIA (1990)

    Google Scholar 

  18. Glew, N.: Type dispatch for named hierarchical types. In: ICFP, pp. 172–182 (1999)

    Google Scholar 

  19. Leroy, X.: The bytecode interpreter. version 1.96, in OCaml distribution (2006), byterun/interp.c

    Google Scholar 

  20. Leroy, X.: Ocaml-callcc: call/cc for ocaml (2005), http://pauillac.inria.fr/~xleroy/software.html#callcc

  21. Gasbichler, M., Sperber, M.: Final shift for call/cc: Direct implementation of shift and reset. In: ICFP, pp. 271–282 (2002)

    Google Scholar 

  22. Filinski, A.: Representing monads. In: POPL, pp. 446–457 (1994)

    Google Scholar 

  23. Masuko, M., Asai, K.: Direct implementation of shift and reset in the MinCaml compiler. In: ACM SIGPLAN Workshop on ML (2009)

    Google Scholar 

  24. Rompf, T., Maier, I., Odersky, M.: Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform. In: ICFP, pp. 317–328 (2009)

    Google Scholar 

  25. Clinger, W.D., Hartheimer, A.H., Ost, E.M.: Implementation strategies for first-class continuations. Higher-Order and Symbolic Computation 12, 7–45 (1999)

    Article  MATH  Google Scholar 

  26. Sekiguchi, T., Sakamoto, T., Yonezawa, A.: Portable implementation of continuation operators in imperative languages by exception handling. In: Romanovsky, A., Dony, C., Knudsen, J.L., Tripathi, A.R. (eds.) ECOOP-WS 2000. LNCS, vol. 2022, pp. 217–233. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  27. Pettyjohn, G., Clements, J., Marshall, J., Krishnamurthi, S., Felleisen, M.: Continuations from generalized stack inspection. In: ICFP, pp. 216–227 (2005)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2010 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Kiselyov, O. (2010). Delimited Control in OCaml, Abstractly and Concretely: System Description. In: Blume, M., Kobayashi, N., Vidal, G. (eds) Functional and Logic Programming. FLOPS 2010. Lecture Notes in Computer Science, vol 6009. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-12251-4_22

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-12251-4_22

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-12250-7

  • Online ISBN: 978-3-642-12251-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics