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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Kiselyov, O.: Native delimited continuations in (byte-code) OCaml (2006), http://okmij.org/ftp/Computation/Continuations.html#caml-shift
Kiselyov, O., Shan, C.-c., Sabry, A.: Delimited dynamic binding. In: ICFP, pp. 26–37 (2006)
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)
Kiselyov, O., Shan, C.-c.: Monolingual probabilistic programming using generalized coroutines. In: Uncertainty in Artificial Intelligence (2009)
Kiselyov, O.: Persistent delimited continuations for CGI programming with nested transactions. Continuation Fest 2008 (2008), http://okmij.org/ftp/Computation/Continuations.html#shift-cgi
Kameyama, Y., Kiselyov, O., Shan, C.-c.: Shifting the stage: Staging with delimited control. In: PEPM, pp. 111–120 (2009)
Kiselyov, O., Shan, C.-c.: Lifted inference: Normalizing loops by evaluation. In: Proc. 2009 Workshop on Normalization by Evaluation, BRICS (2009)
Kiselyov, O.: Ask-by-need: On-demand evaluation with effects (2007), http://okmij.org/ftp/Computation/Continuations.html#ask-by-need
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)
Dybvig, R.K., Peyton Jones, S.L., Sabry, A.: A monadic framework for delimited continuations. J. Functional Progr. 17, 687–730 (2007)
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)
Hieb, R., Dybvig, R.K., Bruggeman, C.: Representing control in the presence of first-class continuations. In: PLDI 1990, pp. 66–77 (1990)
Gunter, C.A., Rémy, D., Riecke, J.G.: Return types for functional continuations (1998), http://pauillac.inria.fr/~remy/work/cupto/
Kiselyov, O.: Zipper in Scheme (2004), comp.lang.scheme, http://okmij.org/ftp/Scheme/zipper-in-scheme.txt
Kiselyov, O.: Zipper as a delimited continuation. Message to the Haskell mailing list (2005), http://okmij.org/ftp/Haskell/Zipper1.lhs
Felleisen, M.: The theory and practice of first-class prompts. In: POPL, pp. 180–190 (1988)
Leroy, X.: The ZINC experiment: An economical implementation of the ML language. Technical Report 117, INRIA (1990)
Glew, N.: Type dispatch for named hierarchical types. In: ICFP, pp. 172–182 (1999)
Leroy, X.: The bytecode interpreter. version 1.96, in OCaml distribution (2006), byterun/interp.c
Leroy, X.: Ocaml-callcc: call/cc for ocaml (2005), http://pauillac.inria.fr/~xleroy/software.html#callcc
Gasbichler, M., Sperber, M.: Final shift for call/cc: Direct implementation of shift and reset. In: ICFP, pp. 271–282 (2002)
Filinski, A.: Representing monads. In: POPL, pp. 446–457 (1994)
Masuko, M., Asai, K.: Direct implementation of shift and reset in the MinCaml compiler. In: ACM SIGPLAN Workshop on ML (2009)
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)
Clinger, W.D., Hartheimer, A.H., Ost, E.M.: Implementation strategies for first-class continuations. Higher-Order and Symbolic Computation 12, 7–45 (1999)
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)
Pettyjohn, G., Clements, J., Marshall, J., Krishnamurthi, S., Felleisen, M.: Continuations from generalized stack inspection. In: ICFP, pp. 216–227 (2005)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)