skip to main content
article

Delimited dynamic binding

Published:16 September 2006Publication History
Skip Abstract Section

Abstract

Dynamic binding and delimited control are useful together in many settings, including Web applications, database cursors, and mobile code. We examine this pair of language features to show that the semantics of their interaction is ill-defined yet not expressive enough for these uses.We solve this open and subtle problem. We formalise a typed language DB+DC that combines a calculus DB of dynamic binding and a calculus DC of delimited control. We argue from theoretical and practical points of view that its semantics should be based on delimited dynamic binding: capturing a delimited continuation closes over part of the dynamic environment, rather than all or none of it; reinstating the captured continuation supplements the dynamic environment, rather than replacing or inheriting it. We introduce a type- and reduction-preserving translation from DB + DC to DC, which proves that delimited control macro-expresses dynamic binding. We use this translation to implement DB+DC in Scheme, OCaml, and Haskell.We extend DB + DC with mutable dynamic variables and a facility to obtain not only the latest binding of a dynamic variable but also older bindings. This facility provides for stack inspection and (more generally) folding over the execution context as an inductive data structure.

References

  1. Ariola, Z. M., Herbelin, H., and Sabry, A. A type-theoretic foundation of continuations and prompts. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (2004), ACM Press, pp. 40--53. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Baker, H. G. Shallow binding in Lisp 1. 5. Communications of the ACM 21, 7 (July 1978), 565--569. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Baker, H. G. Shallow binding makes functional arrays fast. ACM SIGPLAN Notices 26, 8 (Aug. 1991), 145--147. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Balat, V., and Danvy, O. Memoization in type-directed partial evaluation. In ACM SIGPLAN/SIGSOFT Conference on Generative Programming and Component Engineering (2002), D. S. Batory, C. Consel, and W. Taha, Eds., no. 2487 in Lecture Notes in Computer Science, Springer-Verlag, pp. 78--92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Balat, V., Di Cosmo, R., and Fiore, M. Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (2004), ACM Press, pp. 64--76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Bawden, A. Reification without evaluation. Memo 946, Artificial Intelligence Laboratory, Massachusetts Institute of Technology, 1 June 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Biernacka, M., Biernacki, D., and Danvy, O. An operational foundation for delimited continuations in the CPS hierarchy. Logical Methods in Computer Science 1, 2:5 (2005).Google ScholarGoogle ScholarCross RefCross Ref
  8. Biernacki, D., and Danvy, O. From interpreter to logic engine by defunctionalization. In LOPSTR 2003: 13th International Symposium on Logic Based Program Synthesis and Transformation (2004), M. Bruynooghe, Ed., no. 3018 in Lecture Notes in Computer Science, Springer-Verlag, pp. 143--159.Google ScholarGoogle ScholarCross RefCross Ref
  9. Cartwright, R., and Felleisen, M. Extensible denotational language specifications. In Theoretical Aspects of Computer Software: International Symposium (1994), M. Hagiya and J. C. Mitchell, Eds., no. 789 in Lecture Notes in Computer Science, Springer-Verlag, pp. 244--272. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Clements, J., and Felleisen, M. A tail-recursive semantics for stack inspections. In Programming Languages and Systems: Proceedings of ESOP 2003, 12th European Symposium on Programming (2003), P. Degano, Ed., no. 2618 in Lecture Notes in Computer Science, Springer-Verlag, pp. 22--37. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Cobbe, R., and Felleisen, M. Environmental acquisition revisited. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (2005), ACM Press, pp. 14--25. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Danvy, O. Type-directed partial evaluation. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1996), ACM Press, pp. 242--257. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Danvy, O., and Filinski, A. A functional abstraction of typed contexts. Tech. Rep. 89/12, DIKU, University of Copenhagen, Denmark, 1989. http://www.daimi.au.dk/~danvy/Papers/fatc.ps.gz.Google ScholarGoogle Scholar
  14. Danvy, O., and Filinski, A. Abstracting control. In Proceedings of the ACM Conference on Lisp and Functional Programming (27--29 June 1990), ACM Press, pp. 151--160. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Danvy, O., and Filinski, A. Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2, 4 (Dec. 1992), 361--391.Google ScholarGoogle ScholarCross RefCross Ref
  16. Danvy, O., and MalmkjÆr, K. Intensions and extensions in a reflective tower. In Proceedings of the ACM Conference on Lisp and Functional Programming (1988), ACM Press, pp. 327--341. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Dybjer, P., and Filinski, A. Normalization and partial evaluation. In APPSEM 2000: International Summer School on Applied Semantics, Advanced Lectures (2002), G. Barthe, P. Dybjer, L. Pinto, and J. Saraiva, Eds., no. 2395 in Lecture Notes in Computer Science, Springer-Verlag, pp. 137--192. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Dybvig, R. K., Peyton Jones, S. L., and Sabry, A. A monadic framework for delimited continuations. Tech. Rep. 615, Department of Computer Science, Indiana University, June 2005.Google ScholarGoogle Scholar
  19. Feeley, M. Parameter objects. Scheme Request for Implementation SRFI-39. http://srfi.schemers.org/srfi-39/,2003.Google ScholarGoogle Scholar
  20. Felleisen, M. The Calculi of λv-CS Conversion: A Syntactic Theory of Control and State in Imperative Higher-Order Programming Languages. PhD thesis, Computer Science Department, Indiana University, Aug. 1987. Also as Tech. Rep. 226. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Felleisen, M. The theory and practice of first-class prompts. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Jan. 1988), ACM Press, pp. 180--190. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Felleisen, M. On the expressive power of programming languages. Science of Computer Programming 17, 1--3 (1991), 35--75. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Felleisen, M., Friedman, D. P., Duba, B. F., and Merrill, J. Beyond continuations. Tech. Rep. 216, Computer Science Department, Indiana University, Feb. 1987.Google ScholarGoogle Scholar
  24. Filinski, A. Representing monads. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1994), ACM Press, pp. 446--457. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Filinski, A. Representing layered monads. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1999), ACM Press, pp. 175--188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Filinski, A. Normalization by evaluation for the computational lambda-calculus. In Proceedings of the 5th International Conference on Typed Lambda Calculi and Applications (May 2001), S. Abramsky, Ed., no. 2044 in Lecture Notes in Computer Science, Springer-Verlag, pp. 151--165. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Franz Inc. Allegro Common Lisp 8.0, 17 Mar. 2006.Google ScholarGoogle Scholar
  28. Friedman, D. P., and Haynes, C. T. Constraining control. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1985), ACM Press, pp. 245--254. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Gasbichler, M., Knauel, E., Sperber, M., and Kelsey, R. A. How to add threads to a sequential language without getting tangled up. In Proceedings of the 4th Workshop on Scheme and Functional Programming (7 Nov. 2003), M. Flatt, Ed., no. UUCS-03-023 in Tech. Rep., School of Computing, University of Utah, pp. 30--47.Google ScholarGoogle Scholar
  30. Gasbichler, M., and Sperber, M. Processes vs. user-level threads in Scsh. In Proceedings of the 3rd Workshop on Scheme and Functional Programming (3 Oct. 2002).Google ScholarGoogle Scholar
  31. Gil, J., and Lorenz, D. H. Environmental acquisitionùa new inheritance-like abstraction mechanism. In Proceedings of the 11th Conference on Object oriented Programming Systems, Languages, and Applications (6-10 Oct. 1996), vol. 31(10) of ACM SIGPLAN Notices, ACM Press, pp. 214--231. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Graunke, P. T. Web Interactions. PhD thesis, College of Computer Science, Northeastern University, June 2003.Google ScholarGoogle Scholar
  33. Grobauer, B., and Yang, Z. The second Futamura projection for typedirected partial evaluation. Higher-Order and Symbolic Computation 14, 2-3 (2001), 173--219. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Gunter, C. A., RÉmy, D., and Riecke, J. G. A generalization of exceptions and control in ML-like languages. In Functional Programming Languages and Computer Architecture: 7th Conference (26-28 June 1995), S. L. Peyton Jones, Ed., ACM Press, pp. 12--23. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Gunter, C. A., RÉmy, D., and Riecke, J. G. Return types for functional continuations. http://pauillac.inria.fr/~remy/work/cupto/,Sept. 1998.Google ScholarGoogle Scholar
  36. Haynes, C. T., and Friedman, D. P. Embedding continuations in procedural objects. ACM Transactions on Programming Languages and Systems 9, 4 (Oct. 1997), 582--598. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Kameyama, Y., and Hasegawa, M. A sound and complete axiomatization of delimited continuations. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (2003), ACM Press, pp. 177--188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Kiselyov, O. General ways to traverse collections. http://okmij.org/ftp/Scheme/enumerators-callcc.html;http://okmij. org/ftp/Computation/Continuations.html,1Jan.2004.Google ScholarGoogle Scholar
  39. Kiselyov, O., Shan, C. -c., Friedman, D. P., and Sabry, A. Backtracking, interleaving, and terminating monad transformers (functional pearl). In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (2005), ACM Press, pp. 192--203. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Lawall, J. L., and Danvy, O. Continuation-based partial evaluation. In Proceedings of the ACM Conference on Lisp and Functional Programming (1994), ACM Press, pp. 227--238. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Leroy, X., and Pessaux, F. Type-based analysis of uncaught exceptions. ACM Transactions on Programming Languages and Systems 22, 2 (2000), 340--377. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Liang, S., Hudak, P., and Jones, M. Monad transformers and modular interpreters. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1995), ACM Press, pp. 333--343. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Matthews, J. I learned today that PLT Scheme actually has two kinds of thread-local storage boxes. http://keepworkingworkerbee.blogspot.com/2005/08/i-learned-today-that-plt-scheme.html,26Aug.2005.Google ScholarGoogle Scholar
  44. Matthews, J., and Findler, R. B. An operational semantics for R5RS Scheme. In Proceedings of the 6th Workshop on Scheme and Functional Programming (24 Sept. 2005), J.M. Ashley and M. Sperber, Eds., no. 619 in Tech. Rep., Computer Science Department, Indiana University, pp. 41--54.Google ScholarGoogle Scholar
  45. Moggi, E. An abstract view of programming languages. Tech. Rep. ECS-LFCS-90-113, Laboratory for Foundations of Computer Science, Department of Computer Science, University of Edinburgh, 1990.Google ScholarGoogle Scholar
  46. Moreau, L. A syntactic theory of dynamic binding. Higher-Order and Symbolic Computation 11, 3 (1998), 233--279. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Queinnec, C. Continuations and web servers. Higher-Order and Symbolic Computation 17, 4 (Dec. 2004), 277--295. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Sabry, A. Note on axiomatizing the semantics of control operators. Tech. Rep. CIS-TR-96-03, Department of Computer and Information Science, University of Oregon, 1996.Google ScholarGoogle Scholar
  49. Sewell, P., Leifer, J. J., Wansbrough, K., Zappa Nardelli, F., Allen-Williams, M., Habouzit, P., and Vafeiadis, V. Acute: High-level programming language design for distributed computation. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (2005), ACM Press, pp. 15--26. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Sitaram, D. Handling control. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (June 1993), ACM Press, pp. 147--155. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Sitaram, D. Unwind-protect in portable Scheme. In Proceedings of the 4th Workshop on Scheme and Functional Programming (7 Nov. 2003), M. Flatt, Ed., no. UUCS-03-023 in Tech. Rep., School of Computing, University of Utah, pp. 48--52.Google ScholarGoogle Scholar
  52. Sitaram, D., and Felleisen, M. Reasoning with continuations II: Full abstraction for models of control. In Proceedings of the ACM Conference on Lisp and Functional Programming (27-29 June 1990), ACM Press, pp. 161--175. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Smith, B. C. Reflection and Semantics in a Procedural Language. PhD thesis, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, Feb. 1982. Also as Tech. Rep. MIT/LCS/TR-272.Google ScholarGoogle Scholar
  54. Sumii, E. An implementation of transparent migration on standard Scheme. In Proceedings of the Workshop on Scheme and Functional Programming (Sept. 2000), M. Felleisen, Ed., no. 00-368 in Tech. Rep., Department of Computer Science, Rice University, pp. 61--63.Google ScholarGoogle Scholar
  55. Thielecke, H. Contrasting exceptions and continuations. http://www. cs. bham. ac. uk/~hxt/research/exncontjournal. pdf, 2001.Google ScholarGoogle Scholar
  56. Thiemann, P. Combinators for program generation. Journal of Functional Programming 9, 5 (1999), 483--525. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Wand, M., and Friedman, D. P. The mystery of the tower revealed: A non-reflective description of the reflective tower. Lisp and Symbolic Computation 1, 1 (1988), 11--37.Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Delimited dynamic binding

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 41, Issue 9
      Proceedings of the 2006 ICFP conference
      September 2006
      296 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1160074
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming
        September 2006
        308 pages
        ISBN:1595933093
        DOI:10.1145/1159803
        • General Chair:
        • John Reppy,
        • Program Chair:
        • Julia Lawall

      Copyright © 2006 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 16 September 2006

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!