Abstract
Effect handlers encourage programmers to abstract over repeated patterns of complex control flow. As of today, this abstraction comes at a significant price in performance. In this paper, we aim to achieve abstraction without regret for effect handlers.
We present a language for effect handlers in _capability-passing style_ (λCap) and an implementation of this language as a translation to simply-typed lambda calculus in _iterated continuation-passing style_. A suite of benchmarks indicates that the novel combination of capability-passing style and iterated CPS enables significant speedups over existing languages with effect handlers or control operators. Our implementation technique is general and allows us to generate code in any language that supports first-class functions.
We then identify a subset of programs for which we can further improve the performance and guarantee full elimination of the effect handler abstraction. To formally capture this subset, we refine λCap to λ λCap with a more restrictive type system. We present a type-directed translation for λ λCap that inserts staging annotations and prove that no abstractions or applications related to effect handlers occur in the translated program. Using this second translation we observe additional speedups in some of the benchmarks.
Supplemental Material
- Andrei Alexandrescu. 2010. The D Programming Language (1st ed.). Addison-Wesley Professional.Google Scholar
- Brian Anderson, Lars Bergstrom, Manish Goregaokar, Josh Matthews, Keegan McAllister, Jack Mofitt, and Simon Sapin. 2016. Engineering the Servo Web Browser Engine Using Rust. In Proceedings of the 38th International Conference on Software Engineering Companion (Austin, Texas) ( ICSE '16). Association for Computing Machinery, New York, NY, USA, 81-89. https://doi.org/10.1145/2889160.2889229 Google Scholar
Digital Library
- Henk P. Barendregt. 1992. Lambda Calculi with Types. In Handbook of Logic in Computer Science (vol. 2 ): Background: Computational Structures. Oxford University Press, New York, NY, USA, 117-309.Google Scholar
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting Algebraic Efects. Proc. ACM Program. Lang. 3, POPL, Article 6 ( Jan. 2019 ), 28 pages.Google Scholar
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2020. Binders by Day, Labels by Night: Efect Instances via Lexically Scoped Handlers. In Proceedings of the Symposium on Principles of Programming Languages (to appear). ACM, New York, NY, USA.Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser and Philipp Schuster. 2017. Efekt: Extensible Algebraic Efects in Scala (Short Paper). In Proceedings of the International Symposium on Scala (Vancouver, BC, Canada). ACM, New York, NY, USA. https: //doi.org/10.1145/3136000.3136007 Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Efect Handlers for the Masses. Proc. ACM Program. Lang. 2, OOPSLA, Article 111 (Oct. 2018 ), 27 pages. https://doi.org/10.1145/3276481 Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Efekt: Capability-Passing Style for Typeand Efect-safe, Extensible Efect Handlers in Scala. Journal of Functional Programming ( 2020 ). https://doi.org/10.1017/ S0956796820000027 Google Scholar
Cross Ref
- Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23, 5 ( 2013 ), 552-593.Google Scholar
Cross Ref
- Oliver Bračevac, Nada Amin, Guido Salvaneschi, Sebastian Erdweg, Patrick Eugster, and Mira Mezini. 2018. Versatile Event Correlation with Algebraic Efects. Proc. ACM Program. Lang. 2, ICFP, Article 67 ( July 2018 ), 31 pages.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, Article 79 ( July 2019 ), 28 pages. https://doi.org/10.1145/3341643 Google Scholar
Digital Library
- Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo Bee Doo Bee Doo. Journal of Functional Programming 30 ( 2020 ), e9. https://doi.org/10.1017/S0956796820000039 Google Scholar
Cross Ref
- Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts. DIKU Rapport 89 /12, DIKU, University of Copenhagen ( 1989 ).Google Scholar
- Olivier Danvy and Andrzej Filinski. 1990. Abstracting Control. In Proceedings of the Conference on LISP and Functional Programming (Nice, France). ACM, New York, NY, USA, 151-160.Google Scholar
- Oliver Danvy and Andrzej Filinski. 1992. Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2, 4 ( 1992 ), 361-391.Google Scholar
- Olivier Danvy, Karoline Malmkjaer, and Jens Palsberg. 1996. Eta-expansion Does The Trick. ACM Trans. Program. Lang. Syst. 18, 6 (Nov. 1996 ), 730-751.Google Scholar
Digital Library
- Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2017. Concurrent system programming with efect handlers. In Proceedings of the Symposium on Trends in Functional Programming. Springer LNCS 10788.Google Scholar
- Stephen Dolan, Leo White, and Anil Madhavapeddy. 2014. Multicore OCaml. In OCaml Workshop.Google Scholar
- Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. 2015. Efective concurrency through algebraic efects. In OCaml Workshop.Google Scholar
- R. Kent Dybvig. 2006. The Development of Chez Scheme. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming (Portland, Oregon, USA) ( ICFP '06). ACM, New York, NY, USA, 1-12. https: //doi.org/10.1145/1159803.1159805 Google Scholar
Digital Library
- R. Kent Dybvig, Simon L. Peyton Jones, and Amr Sabry. 2007. A monadic framework for delimited continuations. Journal of Functional Programming 17, 6 ( 2007 ), 687-730.Google Scholar
- Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2017. On the Expressive Power of User-defined Efects: Efect Handlers, Monadic Reflection, Delimited Control. Proc. ACM Program. Lang. 1, ICFP, Article 13 ( Aug. 2017 ), 29 pages.Google Scholar
- Daniel Hillerström and Sam Lindley. 2016. Liberating Efects with Rows and Handlers. In Proceedings of the Workshop on Type-Driven Development (Nara, Japan). ACM, New York, NY, USA.Google Scholar
Digital Library
- Daniel Hillerström, Sam Lindley, Bob Atkey, and KC Sivaramakrishnan. 2017. Continuation Passing Style for Efect Handlers. In Formal Structures for Computation and Deduction (LIPIcs), Vol. 84. Schloss Dagstuhl-Leibniz-Zentrum für Informatik.Google Scholar
- Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, Inc., Upper Saddle River, New Jersey, USA.Google Scholar
Digital Library
- Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in Action. In Proceedings of the International Conference on Functional Programming (Boston, Massachusetts, USA). ACM, New York, NY, USA, 145-158.Google Scholar
Digital Library
- Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic efects and handlers. Journal of Functional Programming 27, 1 (Jan. 2017 ).Google Scholar
Cross Ref
- Andrew Kennedy. 2007. Compiling with Continuations, Continued. In Proceedings of the International Conference on Functional Programming (Freiburg, Germany). ACM, New York, NY, USA, 177-190.Google Scholar
- Oleg Kiselyov and Hiromi Ishii. 2015. Freer Monads, More Extensible Efects. In Proceedings of the Haskell Symposium (Vancouver, BC, Canada). ACM, New York, NY, USA, 94-105.Google Scholar
- Oleg Kiselyov and KC Sivaramakrishnan. 2018. Ef Directly in OCaml. In Proceedings of the ML Family Workshop / OCaml Users and Developers workshops (Electronic Proceedings in Theoretical Computer Science), Kenichi Asai and Mark Shinwell (Eds.), Vol. 285. Open Publishing Association, 23-58. https://doi.org/10.4204/EPTCS.285.2 Google Scholar
Cross Ref
- Daan Leijen. 2017a. Implementing Algebraic Efects in C. In Proceedings of the Asian Symposium on Programming Languages and Systems. Springer International Publishing, Cham, Switzerland, 339-363.Google Scholar
Cross Ref
- Daan Leijen. 2017b. Structured Asynchrony with Algebraic Efects. In Proceedings of the Workshop on Type-Driven Development (Oxford, UK). ACM, New York, NY, USA, 16-29.Google Scholar
- Daan Leijen. 2017c. Type directed compilation of row-typed algebraic efects. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA, 486-499.Google Scholar
- Daan Leijen. 2018. First Class Dynamic Efect Handlers: Or, Polymorphic Heaps with Dynamic Efect Handlers. In Proceedings of the Workshop on Type-Driven Development (St. Louis, Missouri, USA). ACM, New York, NY, USA, 51-64.Google Scholar
- Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2017. The OCaml system release 4.06. Institut National de Recherche en Informatique et en Automatique ( 2017 ).Google Scholar
- Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Information and Computation 185, 2 ( 2003 ), 182-210.Google Scholar
- Sheng Liang, Paul Hudak, and Mark Jones. 1995. Monad Transformers and Modular Interpreters. In Proceedings of the Symposium on Principles of Programming Languages (San Francisco, California, USA). ACM, New York, NY, USA, 333-343.Google Scholar
Digital Library
- Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do Be Do Be Do. In Proceedings of the Symposium on Principles of Programming Languages (Paris, France). ACM, New York, NY, USA, 500-514.Google Scholar
Digital Library
- Marek Materzok and Dariusz Biernacki. 2012. A dynamic interpretation of the CPS hierarchy. In Proceedings of the Asian Symposium on Programming Languages and Systems. Springer, 296-311.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 (Barcelona, Spain) ( PLDI 2017). ACM, New York, NY, USA, 482-494. https://doi.org/10.1145/3062341.3062380 Google Scholar
Digital Library
- Flemming Nielson and Hanne Riis Nielson. 1996. Multi-level lambda-calculi: an algebraic description. In Partial evaluation. Springer, 338-354.Google Scholar
- Leo Osvald, Grégory Essertel, Xilun Wu, Lilliam I González Alayón, and Tiark Rompf. 2016. Gentrification gone too far? afordable 2nd-class values for fun and (co-) efect. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. ACM, New York, NY, USA, 234-251.Google Scholar
- Frank Pfenning and Conal Elliot. 1988. Higher-Order Abstract Syntax. In Proceedings of the Conference on Programming Language Design and Implementation (Atlanta, Georgia, USA). ACM, New York, NY, USA, 199-208. https://doi.org/10. 1145/53990.54010 Google Scholar
Digital Library
- Maciej Piróg, Tom Schrijvers, Nicolas Wu, and Mauro Jaskeliof. 2018. Syntax and Semantics for Operations with Scopes. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (Oxford, United Kingdom) (LICS '18). ACM, New York, NY, USA, 809-818. https://doi.org/10.1145/3209108.3209166 Google Scholar
Digital Library
- Gordon Plotkin and Matija Pretnar. 2009. Handlers of algebraic efects. In European Symposium on Programming. SpringerVerlag, 80-94.Google Scholar
- Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Efects. Logical Methods in Computer Science 9, 4 ( 2013 ).Google Scholar
- Matija Pretnar. 2015. An introduction to algebraic efects and handlers. invited tutorial paper. Electronic Notes in Theoretical Computer Science 319 ( 2015 ), 19-35.Google Scholar
- Matija Pretnar, Amr Hany Shehata Saleh, Axel Faes, and Tom Schrijvers. 2017. Eficient compilation of algebraic efects and handlers. Technical Report. Department of Computer Science, KU Leuven; Leuven, Belgium.Google Scholar
- John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM annual conference (Boston, Massachusetts, USA). ACM, New York, NY, USA, 717-740.Google Scholar
Digital Library
- Amr Hany Saleh, Georgios Karachalias, Matija Pretnar, and Tom Schrijvers. 2018. Explicit Efect Subtyping. In Programming Languages and Systems, Amal Ahmed (Ed.). Springer International Publishing, Cham, Switzerland, 327-354.Google Scholar
- Philipp Schuster and Jonathan Immanuel Brachthäuser. 2018. Typing, Representing, and Abstracting Control. In Proceedings of the Workshop on Type-Driven Development (St. Louis, Missouri, USA). ACM, New York, NY, USA, 14-24. https: //doi.org/10.1145/3240719.3241788 Google Scholar
Digital Library
- Bjarne Stroustrup. 1997. The C+ + Programming Language, Third Edition (3rd ed.). Addison-Wesley Longman Publishing Co., Inc., USA.Google Scholar
- Walid Taha and Tim Sheard. 1997. Multi-stage Programming with Explicit Annotations. In Proceedings of the Workshop on Partial Evaluation and Program Manipulation (Amsterdam, The Netherlands). ACM, New York, NY, USA, 203-217.Google Scholar
Digital Library
- Walid Taha and Tim Sheard. 2000. MetaML and Multi-stage Programming with Explicit Annotations. Theoretical Computer Science 248, 1-2 (Oct. 2000 ), 211-242. http://dx.doi.org/10.1016/S0304-3975 ( 00 ) 00053-0 Google Scholar
Cross Ref
- Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1 (Nov. 1994 ), 38-94.Google Scholar
Digital Library
- Nicolas Wu and Tom Schrijvers. 2015. Fusion for Free-Eficient Algebraic Efect Handlers. In Proceedings of the Conference on Mathematics of Program Construction (Königswinter, Germany). Springer LNCS 9129.Google Scholar
- Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe Efect Handlers via Tunneling. Proc. ACM Program. Lang. 3, POPL, Article 5 ( Jan. 2019 ), 29 pages.Google Scholar
Index Terms
Compiling effect handlers in capability-passing style
Recommendations
Effects as capabilities: effect handlers and lightweight effect polymorphism
Effect handlers have recently gained popularity amongst programming language researchers. Existing type- and effect systems for effect handlers are often complicated and potentially hinder a wide-spread adoption.
We present the language Effekt with ...
A typed continuation-passing translation for lexical effect handlers
PLDI 2022: Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and ImplementationEffect handlers are a language feature which enjoys popularity in academia and is also gaining traction in industry. Programs use abstract effect operations and handlers provide meaning to them in a delimited scope. Each effect operation is handled ...
Handlers in action
ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programmingPlotkin and Pretnar's handlers for algebraic effects occupy a sweet spot in the design space of abstractions for effectful computation. By separating effect signatures from their implementation, algebraic effects provide a high degree of modularity, ...






Comments