skip to main content
research-article
Open Access

Back to Direct Style: Typed and Tight

Published:06 April 2023Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarCross RefCross Ref
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarCross RefCross Ref
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarCross RefCross Ref
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Olivier Danvy and Frank Pfenning. 1995. The Occurrence of Continuation Parameters in CPS Terms. Department of Computer Science, Carnegie Mellon University. Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarCross RefCross Ref
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarCross RefCross Ref
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarCross RefCross Ref
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle Scholar
  28. 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 ScholarGoogle ScholarCross RefCross Ref
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Back to Direct Style: Typed and Tight

          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 Proceedings of the ACM on Programming Languages
            Proceedings of the ACM on Programming Languages  Volume 7, Issue OOPSLA1
            April 2023
            901 pages
            EISSN:2475-1421
            DOI:10.1145/3554309
            Issue’s Table of Contents

            Copyright © 2023 Owner/Author

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 6 April 2023
            Published in pacmpl Volume 7, Issue OOPSLA1

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article
          • Article Metrics

            • Downloads (Last 12 months)138
            • Downloads (Last 6 weeks)50

            Other Metrics

          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!