Abstract
Transformation of programs into continuation-passing style (CPS) reveals the notion of continuations, enabling many applications such as control operators and intermediate representations in compilers. Although type preservation makes CPS transformation more beneficial, achieving type-preserving CPS transformation for implicit polymorphism with call-by-value (CBV) semantics is known to be challenging. We identify the difficulty in the problem that we call scope intrusion. To address this problem, we propose a new CPS target language Λopen that supports two additional constructs for polymorphism: one only binds and the other only generalizes type variables. Unfortunately, their unrestricted use makes Λopen unsafe due to undesired generalization of type variables. We thus equip Λopen with affine types to allow only the type-safe generalization. We then define a CPS transformation from Curry-style CBV System F to type-safe Λopen and prove that the transformation is meaning and type preserving. We also study parametricity of Λopen as it is a fundamental property of polymorphic languages and plays a key role in applications of CPS transformation. To establish parametricity, we construct a parametric, step-indexed Kripke logical relation for Λopen and prove that it satisfies the Fundamental Property as well as soundness with respect to contextual equivalence.
Supplemental Material
Available for Download
This material provides the full definitions, auxiliary lemmas, and proofs that are omitted in our paper “CPS Transformation with Affine Types for Call-By-Value Implicit Polymorphism” at ICFP 2021.
- Amal Ahmed and Matthias Blume. 2011. An equivalence-preserving CPS translation via multi-language semantics. In ACM SIGPLAN international conference on Functional Programming, ICFP 2011. 431–444. https://doi.org/10.1145/2034773.2034830 Google Scholar
Digital Library
- Amal Ahmed, Derek Dreyer, and Andreas Rossberg. 2009. State-dependent representation independence. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009. 340–353. https://doi.org/10.1145/1480881.1480925 Google Scholar
Digital Library
- Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for free for free: parametricity, with and without types. Proc. ACM Program. Lang., 1, ICFP (2017), 39:1–39:28. https://doi.org/10.1145/3110283 Google Scholar
Digital Library
- Amal J. Ahmed. 2006. Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types. In Programming Languages and Systems, 15th European Symposium on Programming, ESOP 2006, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2006, Vienna, Austria, March 27-28, 2006, Proceedings (Lecture Notes in Computer Science, Vol. 3924). Springer, 69–83. https://doi.org/10.1007/11693024_6 Google Scholar
Digital Library
- Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press. isbn:0-521-41695-7Google Scholar
Digital Library
- Andrew W. Appel and David B. MacQueen. 1991. Standard ML of New Jersey. In Programming Language Implementation and Logic Programming, 3rd International Symposium, PLILP 1991, Proceedings. 1–13. https://doi.org/10.1007/3-540-54444-5_83 Google Scholar
Cross Ref
- Andrew W. Appel and David A. McAllester. 2001. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. Program. Lang. Syst., 23, 5 (2001), 657–683. https://doi.org/10.1145/504709.504712 Google Scholar
Digital Library
- Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018. 56–65. https://doi.org/10.1145/3209108.3209189 Google Scholar
Digital Library
- Andrew Barber and Gordon D. Plotkin. 1996. Dual Intuitionistic Linear Logic. ECS-LFCS-96-347.Google Scholar
- Josh Berdine, Peter W. O’Hearn, Uday S. Reddy, and Hayo Thielecke. 2001. Linearly Used Continuations. In Proceedings of the Third ACM SIGPLAN Workshop on Continuations (CW’01). 47–54. https://www.microsoft.com/en-us/research/publication/linearly-used-continuations/Google Scholar
- Josh Berdine, Peter W. O’Hearn, Uday S. Reddy, and Hayo Thielecke. 2002. Linear Continuation-Passing. High. Order Symb. Comput., 15, 2-3 (2002), 181–208. https://doi.org/10.1023/A:1020891112409 Google Scholar
Digital Library
- Joshua James Berdine. 2004. Linear and Affine Typing of Continuation-Passing Style. RR-04-04.Google Scholar
- Dariusz Biernacki, Olivier Danvy, and Kevin Millikin. 2015. A Dynamic Continuation-Passing Style for Dynamic Delimited Continuations. ACM Trans. Program. Lang. Syst., 38, 1 (2015), 2:1–2:25. https://doi.org/10.1145/2794078 Google Scholar
Digital Library
- William J. Bowman, Youyou Cong, Nick Rioux, and Amal Ahmed. 2018. Type-preserving CPS translation of Σ and Π types is not not possible. Proc. ACM Program. Lang., 2, POPL (2018), 22:1–22:33. https://doi.org/10.1145/3158110 Google Scholar
Digital Library
- Iliano Cervesato and Frank Pfenning. 1996. A Linear Logical Framework. In Proceedings, 11th Annual IEEE Symposium on Logic in Computer Science, LICS 1996. 264–275. https://doi.org/10.1109/LICS.1996.561339 Google Scholar
Cross Ref
- 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), 79:1–79:28. https://doi.org/10.1145/3341643 Google Scholar
Digital Library
- Olivier Danvy. 1992. Three Steps for the CPS Transformation. CIS-92-2.Google Scholar
- Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts.Google Scholar
- Olivier Danvy and Andrzej Filinski. 1990. Abstracting Control. In LISP and Functional Programming. 151–160. https://doi.org/10.1145/91556.91622 Google Scholar
Digital Library
- Olivier Danvy and John Hatcliff. 1992. Thunks (Continued). In Actes WSA’92 Workshop on Static Analysis (Bordeaux, France), September 1992, Laboratoire Bordelais de Recherche en Informatique (LaBRI), Proceedings. 3–11.Google Scholar
- Matthias Felleisen, Daniel P. Friedman, Eugene E. Kohlbecker, and Bruce F. Duba. 1986. Reasoning with Continuations. In Proceedings of the Symposium on Logic in Computer Science (LICS ’86). 131–141.Google Scholar
- Matthias Felleisen and Robert Hieb. 1992. The Revised Report on the Syntactic Theories of Sequential Control and State. Theorical Computer Science, 103, 2 (1992), 235–271. https://doi.org/10.1016/0304-3975(92)90014-7 Google Scholar
Digital Library
- Michael J. Fischer. 1972. Lambda Calculus Schemata. In Proceedings of ACM Conference on Proving Assertions about Programs. 104–109. https://doi.org/10.1145/800235.807077 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’93 Conference on Programming Language Design and Implementation (PLDI). 237–247. https://doi.org/10.1145/155090.155113 Google Scholar
Digital Library
- Matthew Fluet and Stephen Weeks. 2001. Contification Using Dominators. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP ’01). 2–13. https://doi.org/10.1145/507635.507639 Google Scholar
Digital Library
- Daniel P. Friedman and Christopher T. Haynes. 1985. Constraining Control. In Conference Record of the Twelfth Annual ACM Symposium on Principles of Programming Languages, New Orleans, Louisiana, USA, January 1985, Mary S. Van Deusen, Zvi Galil, and Brian K. Reid (Eds.). ACM Press, 245–254. https://doi.org/10.1145/318593.318654 Google Scholar
Digital Library
- Jacques Garrigue. 2004. Relaxing the Value Restriction. In Functional and Logic Programming, 7th International Symposium, FLOPS 2004, Proceedings. 196–213. https://doi.org/10.1007/978-3-540-24754-8_15 Google Scholar
Cross Ref
- Jean-Yves Girard. 1987. Linear Logic. Theor. Comput. Sci., 50 (1987), 1–102. https://doi.org/10.1016/0304-3975(87)90045-4 Google Scholar
Digital Library
- J. Y. Girard. 1972. Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. Université Paris 7.Google Scholar
- Michael J. C. Gordon, Robin Milner, and Christopher P. Wadsworth. 1979. Edinburgh LCF (Lecture Notes in Computer Science, Vol. 78). Springer. isbn:3-540-09724-4 https://doi.org/10.1007/3-540-09724-4 Google Scholar
- Robert Harper and Mark Lillibridge. 1991. ML with callcc is unsound. Announcement on the types electronic forum. https://www.cis.upenn.edu/~bcpierce/types/archives/1991/msg00034.htmlGoogle Scholar
- Robert Harper and Mark Lillibridge. 1993. Explicit Polymorphism and CPS Conversion. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 206–219. https://doi.org/10.1145/158511.158630 Google Scholar
Digital Library
- Robert Harper and Mark Lillibridge. 1993. Polymorphic Type Assignment and CPS Conversion. Lisp and Symbolic Computation, 6, 3-4 (1993), 361–380.Google Scholar
Digital Library
- Masahito Hasegawa. 2002. Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus. In Functional and Logic Programming, 6th International Symposium, FLOPS 2002. 167–182. https://doi.org/10.1007/3-540-45788-7_10 Google Scholar
Cross Ref
- Daniel Hillerström, Sam Lindley, Robert Atkey, and K. C. Sivaramakrishnan. 2017. Continuation Passing Style for Effect Handlers. In 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017. 18:1–18:19. https://doi.org/10.4230/LIPIcs.FSCD.2017.18 Google Scholar
Cross Ref
- My Hoang, John C. Mitchell, and Ramesh Viswanathan. 1993. Standard ML-NJ weak polymorphism and imperative constructs. In Proceedings of the Eighth Annual Symposium on Logic in Computer Science (LICS ’93). 15–25. https://doi.org/10.1109/LICS.1993.287604 Google Scholar
Cross Ref
- Atsushi Igarashi and Naoki Kobayashi. 1997. Type-Based Analysis of Communication for Concurrent Programming Languages. In Static Analysis, 4th International Symposium, SAS ’97. 187–201. https://doi.org/10.1007/BFb0032742 Google Scholar
Cross Ref
- Yukiyoshi Kameyama and Takuo Yonezawa. 2008. Typed Dynamic Control Operators for Delimited Continuations. In Functional and Logic Programming, 9th International Symposium, FLOPS 2008. 239–254. https://doi.org/10.1007/978-3-540-78969-7_18 Google Scholar
- Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. Journal of Functional Programming, 27 (2017), e7. https://doi.org/10.1017/S0956796816000320 Google Scholar
Cross Ref
- Andrew Kennedy. 2007. Compiling with continuations, continued. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007. 177–190. https://doi.org/10.1145/1291151.1291179 Google Scholar
Digital Library
- Naoki Kobayashi. 2013. Model Checking Higher-Order Programs. J. ACM, 60, 3 (2013), 20:1–20:62. https://doi.org/10.1145/2487241.2487246 Google Scholar
Digital Library
- Roland Leiß a, Marcel Köster, and Sebastian Hack. 2015. A graph-based higher-order intermediate representation. In Proceedings of the 13th Annual IEEE/ACM International Symposium on Code Generation and Optimization, CGO 2015. 202–212. https://doi.org/10.1109/CGO.2015.7054200 Google Scholar
Cross Ref
- Daniel Leivant. 1983. Polymorphic Type Inference. In Conference Record of the Tenth Annual ACM Symposium on Principles of Programming Languages, POPL 1983. 88–98. https://doi.org/10.1145/567067.567077 Google Scholar
Digital Library
- Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2020. The OCaml system release 4.10: Documentation and user’s manua. https://caml.inria.fr/pub/docs/manual-ocaml/Google Scholar
- Xavier Leroy and Pierre Weis. 1991. Polymorphic Type Inference and Assignment. In Proceedings of the 18th Annual ACM Symposium on Principles of Programming Languages. 291–302. https://doi.org/10.1145/99583.99622 Google Scholar
Digital Library
- John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. 1995. Call-by-name, call-by-value, call-by-need and the linear lambda calculus. In Eleventh Annual Conference on Mathematical Foundations of Programming Semantics, MFPS 1995. 370–392. https://doi.org/10.1016/S1571-0661(04)00022-2 Google Scholar
Cross Ref
- Albert R. Meyer and Mitchell Wand. 1985. Continuation Semantics in Typed Lambda-Calculi (Summary). In Logics of Programs. 219–224. https://doi.org/10.1007/3-540-15648-8_17 Google Scholar
Cross Ref
- Robin Milner, Joachim Parrow, and David Walker. 1992. A Calculus of Mobile Processes, I. Inf. Comput., 100, 1 (1992), 1–40. https://doi.org/10.1016/0890-5401(92)90008-4 Google Scholar
Digital Library
- Eugenio Moggi. 1989. Computational Lambda-Calculus and Monads. In Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS ’89), Pacific Grove, California, USA, June 5-8, 1989. 14–23. https://doi.org/10.1109/LICS.1989.39155 Google Scholar
- Benoît Montagu and Didier Rémy. 2009. Modeling abstract types in modules with open existential types. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009. 354–365. https://doi.org/10.1145/1480881.1480926 Google Scholar
Digital Library
- James H. Morris. 1969. Lambda-calculus models of programming languages. Ph.D. Dissertation. Massachusetts Institute of Technology. https://dspace.mit.edu/handle/1721.1/64850Google Scholar
- J. Gregory Morrisett, David Walker, Karl Crary, and Neal Glew. 1999. From system F to typed assembly language. ACM Trans. Program. Lang. Syst., 21, 3 (1999), 527–568. https://doi.org/10.1145/319301.319345 Google Scholar
Digital Library
- Georg Neis, Derek Dreyer, and Andreas Rossberg. 2011. Non-parametric parametricity. J. Funct. Program., 21, 4-5 (2011), 497–562. https://doi.org/10.1017/S0956796811000165 Google Scholar
Digital Library
- Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and parametricity: together again for the first time. Proc. ACM Program. Lang., 4, POPL (2020), 46:1–46:32. https://doi.org/10.1145/3371114 Google Scholar
Digital Library
- Simon L. Peyton Jones and Philip Wadler. 1993. Imperative Functional Programming. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 71–84. https://doi.org/10.1145/158511.158524 Google Scholar
Digital Library
- Andrew M. Pitts and Ian David Bede Stark. 1993. Observable Properties of Higher Order Functions that Dynamically Create Local Names, or What’s new? In Mathematical Foundations of Computer Science 1993, 18th International Symposium, MFCS 1993. 122–141. https://doi.org/10.1007/3-540-57182-5_8 Google Scholar
Cross Ref
- Gordon D. Plotkin. 1973. Lambda-definability and logical relations.Google Scholar
- Gordon D. Plotkin. 1975. Call-by-Name, Call-by-Value and the lambda-Calculus. Theor. Comput. Sci., 1, 2 (1975), 125–159. https://doi.org/10.1016/0304-3975(75)90017-1 Google Scholar
Cross Ref
- John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM Annual Conference - Volume 2 (ACM ’72). 717–740. https://doi.org/10.1145/800194.805852 Google Scholar
Digital Library
- John C. Reynolds. 1974. Towards a theory of type structure. In Programming Symposium, Proceedings Colloque sur la Programmation. 408–423. https://doi.org/10.1007/3-540-06859-7_148 Google Scholar
Cross Ref
- John C. Reynolds. 1983. Types, Abstraction and Parametric Polymorphism. In IFIP Congress. 513–523.Google Scholar
- John C. Reynolds. 1993. The Discoveries of Continuations. Lisp and Symbolic Computation, 6, 3-4 (1993), 233–248.Google Scholar
Digital Library
- Amr Sabry and Matthias Felleisen. 1992. Reasoning About Programs in Continuation-Passing Style. In Proceedings of the Conference on Lisp and Functional Programming, LFP 1992. 288–298. https://doi.org/10.1145/141471.141563 Google Scholar
Digital Library
- Taro Sekiyama and Atsushi Igarashi. 2019. Handling Polymorphic Algebraic Effects. In Programming Languages and Systems - 28th European Symposium on Programming, ESOP 2019, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2019, Proceedings. 353–380. https://doi.org/10.1007/978-3-030-17184-1_13 Google Scholar
Cross Ref
- Taro Sekiyama, Takeshi Tsukada, and Atsushi Igarashi. 2020. Signature restriction for polymorphic algebraic effects. Proc. ACM Program. Lang., 4, ICFP (2020), 117:1–117:30. https://doi.org/10.1145/3408999 Google Scholar
Digital Library
- William W. Tait. 1967. Intensional Interpretations of Functionals of Finite Type I. J. Symb. Log., 32, 2 (1967), 198–212. https://doi.org/10.2307/2271658 Google Scholar
Cross Ref
- Hayo Thielecke. 2003. From control effects to typed continuation passing. In Conference Record of POPL 2003: The 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 139–149. https://doi.org/10.1145/640128.604144 Google Scholar
Digital Library
- Hayo Thielecke. 2004. Answer Type Polymorphism in Call-by-Name Continuation Passing. In Programming Languages and Systems, 13th European Symposium on Programming, ESOP 2004, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2004. 279–293. https://doi.org/10.1007/978-3-540-24725-8_20 Google Scholar
Cross Ref
- Mads Tofte. 1990. Type Inference for Polymorphic References. Inf. Comput., 89, 1 (1990), 1–34. https://doi.org/10.1016/0890-5401(90)90018-D Google Scholar
Digital Library
- David N. Turner, Philip Wadler, and Christian Mossin. 1995. Once Upon a Type. In Proceedings of the seventh international conference on Functional programming languages and computer architecture, FPCA 1995. 1–11. https://doi.org/10.1145/224164.224168 Google Scholar
Digital Library
- Philip Wadler. 1989. Theorems for Free!. In Proceedings of the fourth international conference on Functional programming languages and computer architecture, FPCA 1989. 347–359. https://doi.org/10.1145/99370.99404 Google Scholar
Digital Library
- Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), 38–94. https://doi.org/10.1006/inco.1994.1093 Google Scholar
Digital Library
- Jianzhou Zhao, Qi Zhang, and Steve Zdancewic. 2010. Relational Parametricity for a Polymorphic Linear Lambda Calculus. In Programming Languages and Systems - 8th Asian Symposium, APLAS 2010, Shanghai, China, November 28 - December 1, 2010. Proceedings, Kazunori Ueda (Ed.) (Lecture Notes in Computer Science, Vol. 6461). Springer, 344–359. https://doi.org/10.1007/978-3-642-17164-2_24 Google Scholar
Cross Ref
Index Terms
CPS transformation with affine types for call-by-value implicit polymorphism
Recommendations
Type-preserving CPS translation of Σ and Π types is not not possible
Dependently typed languages such as Coq are used to specify and prove functional correctness of source programs, but what we ultimately need are guarantees about correctness of compiled code. By preserving dependent types through each compiler pass, we ...
Practical affine types
POPL '11Alms is a general-purpose programming language that supports practical affine types. To offer the expressiveness of Girard's linear logic while keeping the type system light and convenient, Alms uses expressive kinds that minimize notation while ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...






Comments