Skip to main content
Log in

A static simulation of dynamic delimited control

  • Published:
Higher-Order and Symbolic Computation

Abstract

We present a continuation-passing-style (CPS) transformation for some dynamic delimited-control operators, including Felleisen’s \(\verb|control|\) and \(\verb|prompt|\) , that extends a standard call-by-value CPS transformation. Based on this new transformation, we show how Danvy and Filinski’s static delimited-control operators \(\verb|shift|\) and \(\verb|reset|\) simulate dynamic operators, allaying in passing some skepticism in the literature about the existence of such a simulation. The new CPS transformation and simulation use recursive delimited continuations to avoid undelimited control and the overhead it incurs in implementation and reasoning.

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Abbott, M., Altenkirch, T., Ghani, N., McBride, C.: Derivatives of containers. In: Hofmann, M. (ed.) TLCA 2003: Proceedings of the 6th International Conference on Typed Lambda Calculi and Applications. Lecture Notes in Computer Science, vol. 2701, pp. 16–30. Springer, Berlin (2003)

    Chapter  Google Scholar 

  2. Ager, M.S., Biernacki, D., Danvy, O., Midtgaard, J.: A functional correspondence between evaluators and abstract machines. In: Proceedings of the 5th International Conference on Principles and Practice of Declarative Programming, pp. 8–19. ACM Press, New York (2003)

    Chapter  Google Scholar 

  3. Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between call-by-need evaluators and lazy abstract machines. Inf. Process. Lett. 90(5), 223–232 (2004). Extended version available as BRICS Report RS-04-3

    Article  MathSciNet  Google Scholar 

  4. Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between monadic evaluators and abstract machines for languages with computational effects. Theor. Comput. Sci. 342(1), 149–172 (2005). Extended version available as BRICS Report RS-04-28

    Article  MATH  MathSciNet  Google Scholar 

  5. Ariola, Z.M., Herbelin, H., Sabry, A.: A type-theoretic foundation of continuations and prompts. In: ICFP’04: Proceedings of the ACM International Conference on Functional Programming, pp. 40–53. ACM Press, New York (2004)

    Google Scholar 

  6. Balat, V., Danvy, O.: Memoization in type-directed partial evaluation. In: Batory, D.S., Consel, C., Taha, W. (eds.) Proceedings of GPCE 2002: 1st ACM Conference on Generative Programming and Component Engineering. Lecture Notes in Computer Science, vol. 2487, pp. 78–92. Springer, Berlin (2002)

    Google Scholar 

  7. Balat, V., Di Cosmo, R., Fiore, M.: Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums. In: POPL’04: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 64–76. ACM Press, New York (2004)

    Google Scholar 

  8. Barker, C.: Continuations in natural language. In: Thielecke, H. (ed.) CW’04: Proceedings of the 4th ACM SIGPLAN Continuations Workshop, pp. 1–11. Tech. Rep. CSR-04-1, School of Computer Science, University of Birmingham (2004).

  9. Biernacka, M., Danvy, O.: A syntactic correspondence between context-sensitive calculi and abstract machines. Theor. Comput. Sci. 375(1–3), 76–108 (2007)

    Article  MATH  MathSciNet  Google Scholar 

  10. Biernacka, M., Biernacki, D., Danvy, O.: An operational foundation for delimited continuations in the CPS hierarchy. Log. Methods Comput. Sci. 1(2:5) (2005)

  11. Biernacki, D., Danvy, O.: From interpreter to logic engine by defunctionalization. In: Bruynooghe, M. (ed.) LOPSTR 2003: 13th International Symposium on Logic Based Program Synthesis and Transformation. Lecture Notes in Computer Science, vol. 3018, pp. 143–159. Springer, Berlin (2004)

    Google Scholar 

  12. Biernacki, D., Danvy, O.: A simple proof of a folklore theorem about delimited control. J. Funct. Program. 16(3), 269–280 (2006)

    Article  MATH  MathSciNet  Google Scholar 

  13. Biernacki, D., Danvy, O., Millikin, K.: A dynamic continuation-passing style for dynamic delimited continuations. Report RS-05-16, BRICS, Denmark (2005)

  14. Biernacki, D., Danvy, O., Shan, C.-c.: On the dynamic extent of delimited continuations. Inf. Process. Lett. 96(1), 7–17 (2005)

    Article  MathSciNet  Google Scholar 

  15. Biernacki, D., Danvy, O., Shan, C.-c.: On the static and dynamic extents of delimited continuations. Sci. Comput. Program. 60(3), 274–297 (2006)

    Article  MATH  MathSciNet  Google Scholar 

  16. Clinger, W.D.: Proper tail recursion and space efficiency. In: POPL’98: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 174–185. ACM Press, New York (1998)

    Google Scholar 

  17. Crary, K., Harper, R., Puri, S.: What is a recursive module? In: PLDI’99: Proceedings of the ACM Conference on Programming Language Design and Implementation. ACM SIGPLAN Notices, vol. 34(5), pp. 50–63. ACM Press, New York (1999)

    Google Scholar 

  18. Danvy, O.: Back to direct style. Sci. Comput. Program. 22(3), 183–195 (1994)

    Article  MATH  MathSciNet  Google Scholar 

  19. Danvy, O.: Type-directed partial evaluation. In: POPL’96: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 242–257. ACM Press, New York (1996)

    Google Scholar 

  20. Danvy, O.: On evaluation contexts, continuations, and the rest of the computation. In: Thielecke, H. (ed.) CW’04: Proceedings of the 4th ACM SIGPLAN Continuations Workshop, Tech. Rep. CSR-04-1, School of Computer Science, University of Birmingham (2004)

  21. Danvy, O.: A rational deconstruction of Landin’s SECD machine. In: Grelck, C., Huch, F., Michaelson, G., Trinder, P.W. (eds.) Implementation and Application of Functional Languages: 16th International Workshop, IFL 2004. Lecture Notes in Computer Science, vol. 3474, pp. 52–71. Springer, Berlin (2005)

    Google Scholar 

  22. Danvy, O., Filinski, A.: A functional abstraction of typed contexts. Tech. Rep. 89/12, DIKU, University of Copenhagen, Denmark. http://www.daimi.au.dk/~danvy/Papers/fatc.ps.gz (1989)

  23. Danvy, O., Filinski, A.: Abstracting control. In: Proceedings of the 1990 ACM Conference on Lisp and Functional Programming, pp. 151–160. ACM Press, New York (1990)

    Chapter  Google Scholar 

  24. Danvy, O., Filinski, A.: Representing control: a study of the CPS transformation. Math. Struct. Comput. Sci. 2(4), 361–391 (1992)

    Article  MATH  MathSciNet  Google Scholar 

  25. Danvy, O., Lawall, J.L.: Back to direct style II: first-class continuations. In: Clinger, W.D. (ed.) Proceedings of the 1992 ACM Conference on Lisp and Functional Programming. Lisp Pointers, vol. V(1), pp. 299–310. ACM Press, New York (1992)

    Chapter  Google Scholar 

  26. Danvy, O., Nielsen, L.R.: Defunctionalization at work. In: Proceedings of the 3rd International Conference on Principles and Practice of Declarative Programming, pp. 162–174. ACM Press, New York (2001)

    Chapter  Google Scholar 

  27. Danvy, O., Yang, Z.: An operational investigation of the CPS hierarchy. In: Swierstra, S.D. (ed.) Programming Languages and Systems: Proceedings of ESOP’99, 8th European Symposium on Programming. Lecture Notes in Computer Science, vol. 1576, pp. 224–242. Springer, Berlin (1999)

    Google Scholar 

  28. Double, C.: Partial continuations. http://www.double.co.nz/scheme/partial-continuations/partial- continuations.html (2004)

  29. Dybjer, P., Filinski, A.: Normalization and partial evaluation. In: Barthe, G., Dybjer, P., Pinto, L., Saraiva, J. (eds.) APPSEM 2000: International Summer School on Applied Semantics, Advanced Lectures. Lecture Notes in Computer Science, vol. 2395, pp. 137–192. Springer, Berlin (2002)

    Google Scholar 

  30. Dybvig, R.K., Peyton Jones, S.L., Sabry, A.: A monadic framework for delimited continuations. Tech. Rep. 615, Computer Science Department, Indiana University (2005)

  31. Felleisen, M.: The calculi of λ v -CS conversion: a syntactic theory of control and state in imperative higher-order programming languages. Ph.D. thesis, Computer Science Department, Indiana University. Also as Tech. Rep. 226 (1987)

  32. Felleisen, M.: The theory and practice of first-class prompts. In: POPL’88: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 180–190. ACM Press, New York (1988)

    Google Scholar 

  33. Felleisen, M.: On the expressive power of programming languages. Sci. Comput. Program. 17(1–3), 35–75 (1991)

    Article  MATH  MathSciNet  Google Scholar 

  34. Felleisen, M., Friedman, D.P.: Control operators, the SECD machine, and the λ-calculus. In: Wirsing, M. (ed.) Formal Description of Programming Concepts III, pp. 193–217. Elsevier, Amsterdam (1987)

    Google Scholar 

  35. Felleisen, M., Friedman, D.P., Duba, B.F., Merrill, J.: Beyond continuations. Tech. Rep. 216, Computer Science Department, Indiana University (1987)

  36. Felleisen, M., Wand, M., Friedman, D.P., Duba, B.F.: Abstract continuations: a mathematical semantics for handling full jumps. In: Proceedings of the 1988 ACM Conference on Lisp and Functional Programming, pp. 52–62. ACM Press, New York (1988)

    Chapter  Google Scholar 

  37. Filinski, A.: Representing monads. In: POPL’94: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 446–457. ACM Press, New York (1994)

    Google Scholar 

  38. Filinski, A.: Controlling effects. Ph.D. thesis, School of Computer Science, Carnegie Mellon University. Also as Tech. Rep. CMU-CS-96-119 (1996)

  39. Filinski, A.: Representing layered monads. In: POPL’99: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 175–188. ACM Press, New York (1999)

    Google Scholar 

  40. Filinski, A.: Normalization by evaluation for the computational lambda-calculus. In: Abramsky, S. (ed.) TLCA 2001: Proceedings of the 5th International Conference on Typed Lambda Calculi and Applications. Lecture Notes in Computer Science, vol. 2044, pp. 151–165. Springer, Berlin (2001)

    Chapter  Google Scholar 

  41. Friedman, D.P., Haynes, C.T.: Constraining control. In: POPL’85: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 245–254. ACM Press, New York (1985)

    Google Scholar 

  42. Friedman, D.P., Wand, M., Haynes, C.T.: Essentials of Programming Languages, 2nd edn. MIT Press, Cambridge (2001)

    MATH  Google Scholar 

  43. Gapeyev, V., Levin, M.Y., Pierce, B.C.: Recursive subtyping revealed. In: ICFP’00: Proceedings of the ACM International Conference on Functional Programming. ACM SIGPLAN Notices, vol. 35(9), pp. 221–231. ACM Press, New York (2000)

    Google Scholar 

  44. Gasbichler, M., Sperber, M.: Final shift for call/cc: direct implementation of shift and reset. In: ICFP’02: Proceedings of the ACM International Conference on Functional Programming, pp. 271–282. ACM Press, New York (2002)

    Google Scholar 

  45. Graunke, P.T.: Web interactions. Ph.D. thesis, College of Computer Science, Northeastern University (2003)

  46. Grobauer, B., Yang, Z.: The second Futamura projection for type-directed partial evaluation. Higher-Order Symb. Comput. 14(2–3), 173–219 (2001)

    Article  MATH  Google Scholar 

  47. Gunter, C.A., Rémy, D., Riecke, J.G.: A generalization of exceptions and control in ML-like languages. In: Peyton Jones, S.L. (ed.) Functional Programming Languages and Computer Architecture: 7th Conference, pp. 12–23. ACM Press, New York (1995)

    Chapter  Google Scholar 

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

  49. Hieb, R., Dybvig, R.K.: Continuations and concurrency. In: Proceedings of the 2nd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, pp. 128–136. ACM Press, New York (1990)

    Chapter  Google Scholar 

  50. Hinze, R., Jeuring, J.: Weaving a web. J. Funct. Program. 11(6), 681–689 (2001)

    Article  MATH  MathSciNet  Google Scholar 

  51. Huet, G.: The zipper. J. Funct. Program. 7(5), 549–554 (1997)

    Article  MATH  MathSciNet  Google Scholar 

  52. Johnson, G.F., Duggan, D.: Stores and partial continuations as first-class objects in a language and its environment. In: POPL’88: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 158–168. ACM Press, New York (1988)

    Google Scholar 

  53. Kelsey, R., Clinger, W.D., Rees, J., Abelson, H., Dybvig, R.K., Haynes, C.T., Rozas, G.J., Adams IV, N.I., Friedman, D.P., Kohlbecker, E., Steele, G.L., Bartley, D.H., Halstead, R., Oxley, D., Sussman, G.J., Brooks, G., Hanson, C., Pitman, K.M., Wand, M.: Revised5 report on the algorithmic language Scheme. Higher-Order Symb. Comput. 11(1), 7–105 (1998). Also as ACM SIGPLAN Notices 33(9), 26–76

    Article  Google Scholar 

  54. Kiselyov, O.: General ways to traverse collections. http://okmij.org/ftp/Scheme/enumerators-callcc.html; http://okmij.org/ftp/Computation/Continuations.html (2004)

  55. Kiselyov, O.: How to remove a dynamic prompt: static and dynamic delimited continuation operators are equally expressible. Tech. Rep. 611, Computer Science Department, Indiana University (2005)

  56. Kiselyov, O.: Two-hole zippers and transactions of various isolation modes. Message to the Haskell mailing list; http://okmij.org/ftp/Haskell/Zipper2.lhs; http://okmij.org/ftp/Computation/Continuations.html (2005)

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

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

  59. Kiselyov, O., Shan, C.-c., Friedman, D.P., Sabry, A.: Backtracking, interleaving, and terminating monad transformers (functional pearl). In: ICFP’05: Proceedings of the ACM International Conference on Functional Programming, pp. 192–203. ACM Press, New York (2005)

    Google Scholar 

  60. Kiselyov, O., Shan, C.-C., Sabry, A.: Delimited dynamic binding. In: ICFP ’06: Proceedings of the ACM International Conference on Functional Programming, pp. 26–37. ACM Press, New York (2006)

    Chapter  Google Scholar 

  61. Krivine, J.-L.: Un interpréteur du lambda-calcul. http://www.pps.jussieu.fr/~krivine/articles/interprt.pdf (1985)

  62. Landin, P.J.: The mechanical evaluation of expressions. Comput. J. 6(4), 308–320 (1964)

    MATH  Google Scholar 

  63. Lawall, J.L., Danvy, O.: Continuation-based partial evaluation. In: Proceedings of the 1994 ACM Conference on Lisp and Functional Programming, pp. 227–238. ACM Press, New York (1994)

    Chapter  Google Scholar 

  64. Meyer, A.R., Wand, M.: Continuation semantics in typed lambda-calculi (summary). In: Parikh, R. (ed.) Logics of Programs. Lecture Notes in Computer Science, vol. 193, pp. 219–224. Springer, Berlin (1985)

    Google Scholar 

  65. Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991)

    Article  MATH  MathSciNet  Google Scholar 

  66. Murphy VII, T., Crary, K., Harper, R.: Distributed control flow with classical modal logic. In: Ong, C.-H.L. (ed.) Computer Science Logic: 19th International Workshop, CSL 2005. Lecture Notes in Computer Science, vol. 3634, pp. 51–69. Springer, Berlin (2005)

    Google Scholar 

  67. Murthy, C.R.: Control operators, hierarchies, and pseudo-classical type systems: A-translation at work. In: Danvy O., Talcott C. (eds.) CW’92: Proceedings of the ACM SIGPLAN Workshop on Continuations, pp. 49–71. Tech. Rep. STAN-CS-92-1426, Department of Computer Science, Stanford University. ftp://cstr.stanford.edu/pub/cstr/reports/cs/tr/92/1426 (1992)

  68. Plotkin, G.D.: Call-by-name, call-by-value and the λ-calculus. Theor. Comput. Sci. 1(2), 125–159 (1975)

    Article  MATH  MathSciNet  Google Scholar 

  69. Queinnec, C.: A library of high-level control operators. Lisp Pointers 6(4), 11–26 (1993)

    Article  Google Scholar 

  70. Queinnec, C.: Continuations and web servers. Higher-Order Symb. Comput. 17(4), 277–295 (2004)

    Article  Google Scholar 

  71. Queinnec, C., Serpette, B.: A dynamic extent control operator for partial continuations. In: POPL’91: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 174–184. ACM Press, New York (1991)

    Google Scholar 

  72. Reynolds, J.C.: Definitional interpreters for higher-order programming languages. In: Proceedings of the ACM National Conference, vol. 2, pp. 717–740. ACM Press, New York. Reprinted with a foreword in Higher-Order Symb. Comput. 11(4), 363–397 (1972)

    Google Scholar 

  73. Sabry, A., Felleisen, M.: Reasoning about programs in continuation-passing style. Lisp Symb. Comput. 6(3–4), 289–360 (1993)

    Article  Google Scholar 

  74. Sewell, P., Leifer, J.J., Wansbrough, K., Nardelli, F.Z., Allen-Williams, M., Habouzit, P., Vafeiadis, V.: Acute: high-level programming language design for distributed computation. In: ICFP’05: Proceedings of the ACM International Conference on Functional Programming, pp. 15–26. ACM Press, New York (2005)

    Google Scholar 

  75. Shan, C.-c.: Delimited continuations in natural language: quantification and polarity sensitivity. In: Thielecke H. (ed.) CW’04: Proceedings of the 4th ACM SIGPLAN Continuations Workshop, pp. 55–64. Tech. Rep. CSR-04-1, School of Computer Science, University of Birmingham (2004)

  76. Sitaram, D.: Handling control. In: PLDI’93: Proceedings of the ACM Conference on Programming Language Design and Implementation. ACM SIGPLAN Notices, vol. 28(6), pp. 147–155. ACM Press, New York (1993)

    Google Scholar 

  77. Sitaram, D., Felleisen, M.: Control delimiters and their hierarchies. Lisp Symb. Comput. 3(1), 67–99 (1990)

    Article  Google Scholar 

  78. Steele, G.L., Jr.: RABBIT: a compiler for SCHEME. Master’s thesis, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology. Also as Memo 474, Artificial Intelligence Laboratory, Massachusetts Institute of Technology (1978)

  79. Strachey, C., Wadsworth, C.P.: Continuations: a mathematical semantics for handling full jumps. Technical Monograph PRG-11, Programming Research Group, Oxford University Computing Laboratory. Reprinted with a foreword in Higher-Order Symb. Comput. 13(1–2), 135–152 (1974)

  80. Sumii, E.: An implementation of transparent migration on standard Scheme. In: Felleisen M. (ed.) Proceedings of the Workshop on Scheme and Functional Programming, pp. 61–63. Tech. Rep. 00-368, Department of Computer Science, Rice University (2000)

  81. Thielecke, H.: Contrasting exceptions and continuations (2001)

  82. Thiemann, P.: Combinators for program generation. J. Funct. Program. 9(5), 483–525 (1999)

    Article  MATH  MathSciNet  Google Scholar 

  83. Wadler, P.L.: Monads and composable continuations. Lisp Symb. Comput. 7(1), 39–56 (1994)

    Article  Google Scholar 

  84. Wand, M.: Continuation-based program transformation strategies. J. ACM 27(1), 164–180 (1980)

    Article  MATH  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Chung-chieh Shan.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Shan, Cc. A static simulation of dynamic delimited control. Higher-Order Symb Comput 20, 371–401 (2007). https://doi.org/10.1007/s10990-007-9010-4

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-007-9010-4

Keywords

Navigation