Abstract
Translating programs into continuation-passing style is a well-studied tool to explicitly deal with the control structure of programs. This is useful, for example, for compilation. In a typed setting, there also is a logical interpretation of such a translation as an embedding of classical logic into intuitionistic logic. A naturally arising question is whether there is an inverse translation back to direct style. The answer to this question depends on how the continuation-passing translation is defined and on the domain of the inverse translation. In general, translating programs from continuation-passing style back to direct style requires the use of control operators to account for the use of continuations in non-trivial ways.
We present two languages, one in direct style and one in continuation-passing style. Both languages are typed and equipped with an abstract machine semantics. Moreover, both languages allow for non-trivial control flow. We further present a translation to continuation-passing style and a translation back to direct style. We show that both translations are type-preserving and also preserve semantics in a very precise way giving an operational correspondence between the two languages. Moreover, we show that the compositions of the translations are well-behaved. In particular, they are syntactic one-sided inverses on the full language and full syntactic inverses when restricted to trivial control flow.
- Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press, New York, NY, USA. isbn:0-521-41695-7 https://doi.org/10.1017/CBO9780511609619
Google Scholar
Cross Ref
- Malgorzata Biernacka, Dariusz Biernacki, and Sergueï Lenglet. 2011. Typing Control Operators in the CPS Hierarchy. In Proceedings of the 13th International ACM SIGPLAN Symposium on Principles and Practices of Declarative Programming (PPDP ’11). Association for Computing Machinery, New York, NY, USA. 149–160. isbn:9781450307765 https://doi.org/10.1145/2003476.2003498
Google Scholar
Digital Library
- Dariusz Biernacki, Mateusz Pyzik, and Filip Sieczkowski. 2020. A Reflection on Continuation-Composing Style. In 5th International Conference on Formal Structures for Computation and Deduction (FSCD 2020), Zena M. Ariola (Ed.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 167). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 18:1–18:17. isbn:978-3-95977-155-9 issn:1868-8969 https://doi.org/10.4230/LIPIcs.FSCD.2020.18
Google Scholar
Cross Ref
- Dariusz Biernacki, Mateusz Pyzik, and Filip Sieczkowski. 2021. Reflecting Stacked Continuations in a Fine-Grained Direct-Style Reduction Theory. In 23rd International Symposium on Principles and Practice of Declarative Programming (PPDP 2021). Association for Computing Machinery, New York, NY, USA. Article 4, 13 pages. isbn:9781450386890 https://doi.org/10.1145/3479394.3479399
Google Scholar
Digital Library
- Edwin Brady. 2020. Idris 2: Quantitative Type Theory in Action. University of St Andrews, Scotland, UK. https://www.type-driven.org.uk/edwinb/papers/idris2.pdf
Google Scholar
- Youyou Cong, Leo Osvald, Grégory M. Essertel, and Tiark Rompf. 2019. Compiling with Continuations, or Without? Whatever.. Proc. ACM Program. Lang., 3, ICFP (2019), Article 79, July, 28 pages. issn:2475-1421 https://doi.org/10.1145/3341643
Google Scholar
Digital Library
- Olivier Danvy. 1992. Back to Direct Style. In Symposium Proceedings on 4th European Symposium on Programming (ESOP’92). Springer-Verlag, Berlin, Heidelberg. 130–150. isbn:0387552537 https://doi.org/10.1007/3-540-55253-7_8
Google Scholar
Cross Ref
- Olivier Danvy and Julia L. Lawall. 1992. Back to Direct Style II: First-Class Continuations. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming (LFP ’92). Association for Computing Machinery, New York, NY, USA. 299–310. isbn:0897914813 https://doi.org/10.1145/141471.141564
Google Scholar
Digital Library
- Olivier Danvy and Lasse R. Nielsen. 2003. A First-Order One-Pass CPS Transformation. Theor. Comput. Sci., 308, 1–3 (2003), Nov., 239–257. issn:0304-3975 https://doi.org/10.1016/S0304-3975(02)00733-8
Google Scholar
Digital Library
- Olivier Danvy and Frank Pfenning. 1995. The Occurrence of Continuation Parameters in CPS Terms. Department of Computer Science, Carnegie Mellon University.
Google Scholar
- Kavon Farvardin and John Reppy. 2020. From Folklore to Fact: Comparing Implementations of Stacks and Continuations. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2020). Association for Computing Machinery, New York, NY, USA. 75–90. isbn:9781450376136 https://doi.org/10.1145/3385412.3385994
Google Scholar
Digital Library
- Matthias Felleisen, Daniel P. Friedman, Eugene Kohlbecker, and Bruce Duba. 1987. A syntactic theory of sequential control. Theoretical Computer Science, 52, 3 (1987), 205–237. issn:0304-3975 https://doi.org/10.1016/0304-3975(87)90109-5
Google Scholar
Digital Library
- Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation (PLDI ’93). Association for Computing Machinery, New York, NY, USA. 237–247. isbn:0897915984 https://doi.org/10.1145/155090.155113
Google Scholar
Digital Library
- Timothy G. Griffin. 1989. A Formulae-as-Type Notion of Control. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’90). Association for Computing Machinery, New York, NY, USA. 47–58. isbn:0897913434 https://doi.org/10.1145/96709.96714
Google Scholar
Digital Library
- John Hatcliff and Olivier Danvy. 1994. A Generic Account of Continuation-Passing Styles. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’94). Association for Computing Machinery, New York, NY, USA. 458–471. isbn:0897916360 https://doi.org/10.1145/174675.178053
Google Scholar
Digital Library
- William A Howard. 1980. The Formulae-as-Types Notion of Construction. To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, 44 (1980), 479–490.
Google Scholar
- Yukiyoshi Kameyama. 2007. Axioms for Control Operators in the CPS Hierarchy. Higher Order Symbol. Comput., 20, 4 (2007), Dec., 339–369. issn:1388-3690 https://doi.org/10.1007/s10990-007-9009-x
Google Scholar
Digital Library
- Yukiyoshi Kameyama and Masahito Hasegawa. 2003. A Sound and Complete Axiomatization of Delimited Continuations. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming (ICFP ’03). Association for Computing Machinery, New York, NY, USA. 177–188. isbn:1581137567 https://doi.org/10.1145/944705.944722
Google Scholar
Digital Library
- Andrew Kennedy. 2007. Compiling with Continuations, Continued. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP ’07). Association for Computing Machinery, New York, NY, USA. 177–190. isbn:9781595938152 https://doi.org/10.1145/1291151.1291179
Google Scholar
Digital Library
- Oleg Kiselyov and Chung-chieh Shan. 2007. A Substructural Type System for Delimited Continuations. In Typed Lambda Calculi and Applications, Simona Ronchi Della Rocca (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 223–239. isbn:978-3-540-73228-0 https://doi.org/10.1007/978-3-540-73228-0_17
Google Scholar
Cross Ref
- Julia L. Lawall and Olivier Danvy. 1993. Separating Stages in the Continuation-Passing Style Transformation. In Proceedings of the 20th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’93). Association for Computing Machinery, New York, NY, USA. 124–136. isbn:0897915607 https://doi.org/10.1145/158511.158613
Google Scholar
Digital Library
- PaulBlain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Information and Computation, 185, 2 (2003), 182–210. issn:0890-5401 https://doi.org/10.1016/S0890-5401(03)00088-9
Google Scholar
Digital Library
- Marek Materzok and Dariusz Biernacki. 2012. A Dynamic Interpretation of the CPS Hierarchy. In Programming Languages and Systems, Ranjit Jhala and Atsushi Igarashi (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 296–311. isbn:978-3-642-35182-2 https://doi.org/10.1007/978-3-642-35182-2_21
Google Scholar
Cross Ref
- Luke Maurer, Paul Downen, Zena M. Ariola, and Simon L. Peyton Jones. 2017. Compiling Without Continuations. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2017). ACM, New York, NY, USA. 482–494. isbn:978-1-4503-4988-8 https://doi.org/10.1145/3062341.3062380
Google Scholar
Digital Library
- Eugenio Moggi. 1989. Computational lambda-calculus and monads. In [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science. 14–23. https://doi.org/10.1109/LICS.1989.39155
Google Scholar
Cross Ref
- Eugenio Moggi. 1991. Notions of computation and monads. Information and Computation, 93, 1 (1991), 55–92. issn:0890-5401 https://doi.org/10.1016/0890-5401(91)90052-4 Selections from 1989 IEEE Symposium on Logic in Computer Science
Google Scholar
Digital Library
- Marius Müller, Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2023. Back to Direct Style: Typed and Tight. University of Tübingen, Germany. https://se.informatik.uni-tuebingen.de/publications/mueller23continuation
Google Scholar
- Lasse R. Nielsen. 2002. A Simple Correctness Proof of the Direct-Style Transformation. BRICS Report Series, 9, 2 (2002), Jan., https://doi.org/10.7146/brics.v9i2.21719
Google Scholar
Cross Ref
- Amr Sabry and Matthias Felleisen. 1992. Reasoning about Programs in Continuation-Passing Style. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming (LFP ’92). Association for Computing Machinery, New York, NY, USA. 288–298. isbn:0897914813 https://doi.org/10.1145/141471.141563
Google Scholar
Digital Library
- Amr Sabry and Matthias Felleisen. 1993. Reasoning about Programs in Continuation-Passing Style. LISP and Symbolic Computation, 6 (1993), 289–360. https://doi.org/10.1007/BF01019462
Google Scholar
Digital Library
- Amr Sabry and Philip Wadler. 1997. A Reflection on Call-by-Value. ACM Trans. Program. Lang. Syst., 19, 6 (1997), Nov., 916–941. issn:0164-0925 https://doi.org/10.1145/267959.269968
Google Scholar
Digital Library
- Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2020. Compiling Effect Handlers in Capability-Passing Style. Proc. ACM Program. Lang., 4, ICFP (2020), Article 93, Aug., 28 pages. https://doi.org/10.1145/3408975
Google Scholar
Digital Library
Index Terms
Back to Direct Style: Typed and Tight
Recommendations
Practical, general parser combinators
PEPM '16: Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program ManipulationParser combinators are a popular approach to parsing where context-free grammars are represented as executable code. However, conventional parser combinators do not support left recursion, and can have worst-case exponential runtime. These limitations ...
CPS Translations and Applications: The Cube and Beyond
Continuation passing style (CPS) translations of typed λ-calculi have numerous applications. However, the range of these applications has been confined by the fact that CPS translations are known for non-dependent type systems only, thus excluding well-...
Reflecting Stacked Continuations in a Fine-Grained Direct-Style Reduction Theory
PPDP 2021: 23rd International Symposium on Principles and Practice of Declarative ProgrammingThe delimited-control operator shift0 has been formally shown to capture the operational semantics of deep handlers for algebraic effects. Its CPS translation generates λ-terms in which continuation composition is not expressed in terms of nested ...






Comments