Answer-Type Modification without Tears: Prompt-Passing Style Translation for Typed Delimited-Control Operators

The salient feature of delimited-control operators is thei r ability to modify answer types during computation. The feature, answer-type modification (ATM for sh ort), allows one to express various interesting programs such as typed printf compactly and nicely, while it makes it difficult to embed these operators in standard functional languages. In this paper, we present a typed translation of delimited-c ontrol operators shift and reset with ATM into a familiar language with multi-prompt shift and reset without ATM, which lets us use ATM in standard languages without modifying the type system. Our translation generalizes Kiselyov’s direct-style implementation of typed printf, which uses two prompts to emulate the modification of answer types, and passes them during computation. We prove that our translation preserves typing. As the naive prompt-passing style translation generates and passes many prompts even for pure terms, we show an optimized translation that generate prompts only when needed, which is also type-preserving. Finally, we give an implementation in the tagless-final style which respects typing by construction.

[1]  Olivier Danvy,et al.  Abstracting control , 1990, LISP and Functional Programming.

[2]  Robert Atkey,et al.  Parameterised notions of computation , 2006, J. Funct. Program..

[3]  Martin Odersky,et al.  Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform , 2009, ICFP.

[4]  Olivier Danvy,et al.  On some Functional Aspects of Control , 1988 .

[5]  Jon L. White Proceedings of the 1992 ACM conference on LISP and functional programming , 1992 .

[6]  Dariusz Biernacki,et al.  Context-based proofs of termination for typed delimited-control operators , 2009, PPDP '09.

[7]  Olivier Danvy,et al.  A first-order one-pass CPS transformation , 2001, Theor. Comput. Sci..

[8]  Oleg Kiselyov Delimited control in OCaml, abstractly and concretely , 2012, Theor. Comput. Sci..

[9]  Oleg Kiselyov,et al.  Typed Tagless Final Interpreters , 2010, SSGIP.

[10]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[11]  Yukiyoshi Kameyama,et al.  Polymorphic Delimited Continuations , 2007, APLAS.

[12]  Kenichi Asai Offline partial evaluation for shift and reset , 2004, PEPM '04.

[13]  Didier Rémy,et al.  A generalization of exceptions and control in ML-like languages , 1995, FPCA '95.

[14]  Philip Wadler,et al.  Monads and composable continuations , 1994, LISP Symb. Comput..

[15]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[16]  Olivier Danvy,et al.  A Functional Abstraction of Typed Contexts , 1989 .

[17]  Matthias Felleisen,et al.  The theory and practice of first-class prompts , 1988, POPL '88.