Abstract
Effect handlers allow the programmer to implement computational effects, such as custom error handling, various forms of lightweight concurrency, and dynamic binding, inside the programming language. We introduce cpp-effects, a C++ library for effect handlers with a typed high-level, object-oriented interface. We demonstrate that effect handlers can be successfully applied in imperative systems programming languages with manual memory management. Through a collection of examples, we explore how to program effectively with effect handlers in C++, discuss the intricacies and challenges of the implementation, and show that despite its limitations, cpp-effects performance is competitive and in some cases even outperforms state-of-the-art approaches such as C++20 coroutines and the libmprompt library for multiprompt delimited control.
- Joe Armstrong, Robert Virding, Claes Wikström, and Mike Williams. 1996. Concurrent Programming in Erlang, Second Edition. Prentice Hall International, Hertfordshire, UK.
Google Scholar
- Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. J. Log. Algebr. Meth. Program., 84, 1 (2015), 108–123. https://doi.org/10.1016/j.jlamp.2014.02.001
Google Scholar
Cross Ref
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting algebraic effects. Proc. ACM Program. Lang., 3, POPL (2019), 6:1–6:28. https://doi.org/10.1145/3290319
Google Scholar
Digital Library
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2020. Binders by day, labels by night: effect instances via lexically scoped handlers. Proc. ACM Program. Lang., 4, POPL (2020), 48:1–48:29. https://doi.org/10.1145/3371116
Google Scholar
Digital Library
- Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul A. Szerlip, Paul Horsfall, and Noah D. Goodman. 2019. Pyro: Deep Universal Probabilistic Programming. J. Mach. Learn. Res., 20 (2019), 28:1–6.
Google Scholar
- Boost. 2022. Boost.context library. https://github.com/boostorg/context
Google Scholar
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Effect handlers for the masses. Proc. ACM Program. Lang., 2, OOPSLA (2018), 111:1–111:27. https://doi.org/10.1145/3276481
Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala. J. Funct. Program., 30 (2020), e8. https://doi.org/10.1017/S0956796820000027
Google Scholar
Cross Ref
- Guillaume Combette and Guillaume Munch-Maccagnoni. 2018. A resource modality for RAII. In LOLA 2018: Workshop on Syntax and Semantics of Low-Level Languages. 1–4.
Google Scholar
- Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo bee doo bee doo. J. Funct. Program., 30 (2020), e9. https://doi.org/10.1017/S0956796820000039
Google Scholar
Cross Ref
- Dan Ghica, Sam Lindley, Marcos Maroñas Bravo, and Maciej Piróg. 2022. High-Level Effect Handlers in C++ (Artifact). https://doi.org/10.1145/3554330
Google Scholar
Digital Library
- GitHub. 2022. Semantic library. https://github.com/github/semantic
Google Scholar
- Daniel Hillerström, Daan Leijen, Sam Lindley, Matija Pretnar, Andreas Rossberg, and KC Sivamarakrishnan. 2022. WebAssembly Typed Continuations Proposal. https://github.com/effect-handlers/wasm-spec/proposals/continuations/Explainer.md
Google Scholar
- Daniel Hillerström and Sam Lindley. 2016. Liberating effects with rows and handlers. In TyDe. https://doi.org/10.1145/2976022.2976033
Google Scholar
Digital Library
- Pablo Inostroza and Tijs van der Storm. 2018. JEff: objects for effect. In Onward!. ACM, 111–124. https://doi.org/10.1145/3276954.3276955
Google Scholar
Digital Library
- Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in action. In ICFP. ACM, 145–158. https://doi.org/10.1145/2544174.2500590
Google Scholar
Digital Library
- Casey Klein, John Clements, Christos Dimoulas, Carl Eastlund, Matthias Felleisen, Matthew Flatt, Jay A. McCarthy, Jon Rafkind, Sam Tobin-Hochstadt, and Robert Bruce Findler. 2012. Run your research: on the effectiveness of lightweight mechanization. In POPL. ACM, 285–296. https://doi.org/10.1145/2103621.2103691
Google Scholar
Digital Library
- Daan Leijen. 2017. Implementing Algebraic Effects in C — "Monads for Free in C". In APLAS (Lecture Notes in Computer Science, Vol. 10695). Springer, 339–363. https://doi.org/10.1007/978-3-319-71237-6_17
Google Scholar
Cross Ref
- Daan Leijen. 2017. Type directed compilation of row-typed algebraic effects. In POPL. ACM, 486–499. https://doi.org/10.1145/3093333.3009872
Google Scholar
Digital Library
- Daan Leijen. 2019. libhandler. https://github.com/koka-lang/libhandler
Google Scholar
- Daan Leijen and KC Sivamarakrishnan. 2022. libmprompt. https://github.com/koka-lang/libmprompt
Google Scholar
- Meta. 2022. React library. https://reactjs.org/
Google Scholar
- Gordon D. Plotkin and John Power. 2001. Semantics for Algebraic Operations. Electr. Notes Theor. Comput. Sci., 45 (2001), 332–345. https://doi.org/10.1016/S1571-0661(04)80970-8
Google Scholar
Cross Ref
- Gordon D. Plotkin and John Power. 2002. Notions of Computation Determine Monads. In FoSSaCS (Lecture Notes in Computer Science, Vol. 2303). Springer, 342–356. https://doi.org/10.1007/3-540-45931-6_24
Google Scholar
Cross Ref
- Gordon D. Plotkin and John Power. 2003. Algebraic Operations and Generic Effects. Applied Categorical Structures, 11, 1 (2003), 69–94. https://doi.org/10.1023/A:1023064908962
Google Scholar
Cross Ref
- Gordon D. Plotkin and Matija Pretnar. 2009. Handlers of Algebraic Effects. In ESOP (Lecture Notes in Computer Science, Vol. 5502). Springer, 80–94. https://doi.org/10.1007/978-3-642-00590-9_7
Google Scholar
Digital Library
- Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science, 9, 4 (2013), https://doi.org/10.2168/LMCS-9(4:23)2013
Google Scholar
Cross Ref
- Andreas Rossberg, Ben L. Titzer, Andreas Haas, Derek L. Schuff, Dan Gohman, Luke Wagner, Alon Zakai, J. F. Bastien, and Michael Holman. 2018. Bringing the web up to speed with WebAssembly. Commun. ACM, 61, 12 (2018), 107–115. https://doi.org/10.1145/3062341.3062363
Google Scholar
Digital Library
- KC Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly, Sadiq Jaffer, and Anil Madhavapeddy. 2021. Retrofitting effect handlers onto OCaml. In PLDI. ACM, 206–221. https://doi.org/10.1145/3453483.3454039
Google Scholar
Digital Library
- WebAssembly Community Group. 2022. WebAssembly Stack Switching Extension. https://github.com/WebAssembly/stack-switching
Google Scholar
- Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. 2020. Effect handlers, evidently. Proc. ACM Program. Lang., 4, ICFP (2020), 99:1–99:29. https://doi.org/10.1145/3408981
Google Scholar
Digital Library
- Ningning Xie and Daan Leijen. 2021. Generalized evidence passing for effect handlers: efficient compilation of effect handlers to C. Proc. ACM Program. Lang., 5, ICFP (2021), 1–30. https://doi.org/10.1145/3473576
Google Scholar
Digital Library
- Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe effect handlers via tunneling. Proc. ACM Program. Lang., 3, POPL (2019), 5:1–5:29. https://doi.org/10.1145/3290318
Google Scholar
Digital Library
Index Terms
High-level effect handlers in C++
Recommendations
First-class names for effect handlers
Algebraic effects and handlers are a promising technique for incorporating composable computational effects into functional programming languages. Effect handlers enable concisely programming with different effects, but they do not offer a convenient ...
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 ...
Effect handlers for the masses
Effect handlers are a program structuring paradigm with rising popularity in the functional programming language community and can express many advanced control flow abstractions. We present the first implementation of effect handlers for Java - an ...






Comments