Skip to main content
Log in

On typing delimited continuations: three new solutions to the printf problem

  • Published:
Higher-Order and Symbolic Computation

Abstract

In “Functional Unparsing” (J. Funct. Program. 8(6):621–625, 1998), Danvy presented a type-safe printf function using continuations and an accumulator to achieve the effect of dependent types. The key technique employed in Danvy’s solution is the non-standard use of continuations: not all of its calls are tail calls, i.e., it uses delimited continuations. Against this backdrop, we present three new solutions to the printf problem: a simpler one that also uses delimited continuations but that does not use an accumulator, and the corresponding two in direct style with the delimited-control operators, shift and reset. These two solutions are the direct-style counterparts of the two continuation-based ones. The last solution pinpoints the essence of Danvy’s solution: shift is used to change the answer type of delimited continuations. Besides providing a new application of shift and reset, the solutions in direct style raise a key issue in the typing of first-class delimited continuations and require Danvy and Filinski’s original type system. The resulting types precisely account for the behavior of printf.

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. Asai, K., Kameyama, Y.: Polymorphic delimited continuations. In: 5th Asian Symposium on Programming Languages and Systems, APLAS 2007. Lecture Notes in Computer Science, vol. 4807, pp. 239–254. Springer, Berlin (2007)

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  3. Danvy, O.: Functional unparsing. J. Funct. Program. 8(6), 621–625 (1998)

    Article  MATH  Google Scholar 

  4. Danvy, O., Filinski, A.: A functional abstraction of typed contexts. Tech. Rep. 89/12, DIKU, University of Copenhagen (1989)

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

    Chapter  Google Scholar 

  6. 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 

  7. Danvy, O., Hatcliff, J.: On the transformation between direct and continuation semantics. In: Proceedings of the 9th International Conference on Mathematical Foundations of Programming Semantics. Lecture Notes in Computer Science, vol. 802, pp. 627–648. Springer, Berlin (1993)

    Google Scholar 

  8. Filinski, A.: Representing monads. In: POPL ’94: Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 446–457. ACM Press, New York (1994)

    Chapter  Google Scholar 

  9. Hinze, R.: Formatting: A class act. J. Funct. Program. 13(5), 935–944 (2003)

    Article  MATH  Google Scholar 

  10. Kameyama, Y., Hasegawa, M.: A sound and complete axiomatization of delimited continuations. In: ICFP ’03: Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming, pp. 177–188. ACM Press, New York (2003)

    Chapter  Google Scholar 

  11. 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 

  12. Steele, G.L.: RABBIT: A compiler for SCHEME. Tech. Rep. AI-TR-474, Massachusetts Institute of Technology, Cambridge, Massachusetts, USA (1978)

  13. Strachey, C., Wadsworth, C.P.: Continuations: A Mathematical Semantics for Handling Full Jumps. Technical Monograph PRG-11, Oxford University Computing Laboratory, Programming Research Group, Oxford, England (1974). Reprinted in Higher-Order Symb. Comput. 13(1/2), 135–152 (2000)

  14. Thielecke, H.: From control effects to typed continuation passing. In: POPL ’03: Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 139–149. ACM Press, New York (2003)

    Chapter  Google Scholar 

  15. Thielecke, H.: Answer type polymorphism in call-by-name continuation passing. In: 13th European Symposium on Programming, ESOP 2004. Lecture Notes in Computer Science, vol. 2986, pp. 279–293. Springer, Berlin (2004)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Kenichi Asai.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Asai, K. On typing delimited continuations: three new solutions to the printf problem. Higher-Order Symb Comput 22, 275–291 (2009). https://doi.org/10.1007/s10990-009-9049-5

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-009-9049-5

Navigation