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.
Similar content being viewed by others
References
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)
Danvy, O.: Back to direct style. Sci. Comput. Program. 22(3), 183–195 (1994)
Danvy, O.: Functional unparsing. J. Funct. Program. 8(6), 621–625 (1998)
Danvy, O., Filinski, A.: A functional abstraction of typed contexts. Tech. Rep. 89/12, DIKU, University of Copenhagen (1989)
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)
Danvy, O., Filinski, A.: Representing control, a study of the CPS transformation. Math. Struct. Comput. Sci. 2(4), 361–391 (1992)
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)
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)
Hinze, R.: Formatting: A class act. J. Funct. Program. 13(5), 935–944 (2003)
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)
Plotkin, G.D.: Call-by-name, call-by-value, and the λ-calculus. Theor. Comput. Sci. 1(2), 125–159 (1975)
Steele, G.L.: RABBIT: A compiler for SCHEME. Tech. Rep. AI-TR-474, Massachusetts Institute of Technology, Cambridge, Massachusetts, USA (1978)
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)
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)
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)
Author information
Authors and Affiliations
Corresponding author
Rights 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
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10990-009-9049-5