Abstract
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 way to program with different instances of the same effect. As a solution to this inconvenience, previous studies have introduced _named effect handlers_, which allow the programmer to distinguish among different effect instances. However, existing formalizations of named handlers are both involved and restrictive, as they employ non-standard mechanisms to prevent the escaping of handler names.
In this paper, we propose a simple and flexible design of named handlers. Specifically, we treat handler names as first-class values, and prevent their escaping while staying within the ordinary λ-calculus. Such a design is enabled by combining named handlers with _scoped effects_, a novel variation of effects that maintain a scope via rank-2 polymorphism. We formalize two combinations of named handlers and scoped effects, and implement them in the Koka programming language. We also present practical applications of named handlers, including a neural network and a unification algorithm.
- Andrej Bauer and Matija Pretnar. 2014. An Effect System for Algebraic Effects and Handlers. Logical Methods in Computer Science, 10, 4 (2014).
Google Scholar
- Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84, 1 (2015), 108–123.
Google Scholar
Cross Ref
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2017. Handle with Care: Relational Interpretation of Algebraic Effects and Handlers. Proc. ACM Program. Lang., 2, POPL’17 issue (2017), Article 8, Dec., 30 pages. issn:2475-1421 https://doi.org/10.1145/3158096
Google Scholar
Digital Library
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Binders by Day, Labels by Night: Effect Instances via Lexically Scoped Handlers. Proc. ACM Program. Lang., 4, POPL (2019), Article 48, Dec., 29 pages. 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 Szerlip, Paul Horsfall, and Noah D Goodman. 2019. Pyro: Deep universal probabilistic programming. The Journal of Machine Learning Research, 20, 1 (2019), 973–978.
Google Scholar
Digital Library
- Oliver Bračevac, Nada Amin, Guido Salvaneschi, Sebastian Erdweg, Patrick Eugster, and Mira Mezini. 2018. Versatile event correlation with algebraic effects. Proceedings of the ACM on Programming Languages, 2, ICFP (2018), 67.
Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Effects as Capabilities: Effect Handlers and Lightweight Effect Polymorphism. Proc. ACM Program. Lang., 5 (2020).
Google Scholar
Digital Library
- Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo bee doo bee doo. In the Journal of Functional Programming, Jan..
Google Scholar
- Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2017. Effectively Tackling the Awkward Squad. In ML Workshop.
Google Scholar
- Derek Dreyer. 2018. The Type Soundness Theorem That You Really Want to Prove (and now you can). Milner Award Lecture, POPL 2018
Google Scholar
- R Kent Dyvbig, Simon Peyton Jones, and Amr Sabry. 2007. A monadic framework for delimited continuations. Journal of Functional Programming, 17, 6 (2007), 687–730. https://doi.org/10.1017/S0956796807006259
Google Scholar
Digital Library
- Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2019. On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control. Journal of Functional Programming, 29 (2019), 15. https://doi.org/10.1017/S0956796819000121 arxiv:1610.09161.
Google Scholar
Cross Ref
- Carl A. Gunter, Didier Rémy, and Jon G. Riecke. 1995. A Generalization of Exceptions and Control in ML-like Languages. In Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture (FPCA ’95). ACM, 12–23. isbn:0897917197
Google Scholar
- Daniel Hillerström and Sam Lindley. 2016. Liberating Effects with Rows and Handlers. In Proceedings of the 1st International Workshop on Type-Driven Development (TyDe 2016). 15–27. https://doi.org/10.1145/2976022.2976033
Google Scholar
Digital Library
- Ralf Hinze. 2003. Fun with phantom types. In The Fun of Programming, Cornerstones of Computing, eremy Gibbons and Oege de Moor (Eds.). Palgrave Macmillan, 245–262. isbn:1-4039-0772-2
Google Scholar
- Mark P. Jones. 1996. Using Parameterized Signatures to Express Modular Structure. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’96). 68–78. isbn:0897917693 https://doi.org/10.1145/237721.237731
Google Scholar
Digital Library
- Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. Journal of Functional Programming, 27, 1 (2017), Jan., https://doi.org/10.1017/S0956796816000320
Google Scholar
Cross Ref
- Oleg Kiselyov, Chung-chieh Shan, and Amr Sabry. 2006. Delimited Dynamic Binding. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming (ICFP ’06). ACM, New York, NY, USA. 26–37. isbn:1-59593-309-3
Google Scholar
Digital Library
- Oleg Kiselyov and KC Sivaramakrishnan. 2017. Eff directly in OCaml. In ML workshop 2016. http://kcsrk.info/papers/caml-eff17.pdf Extended version
Google Scholar
- Koka. 2019. https://github.com/koka-lang/koka
Google Scholar
- Daan Leijen. 2008. HMF: Simple Type Inference for First-Class Polymorphism. In Proceedings of the 13th ACM Symposium of the International Conference on Functional Programming (ICFP’08). https://doi.org/10.1145/1411204.1411245
Google Scholar
Digital Library
- Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In MSFP’14, 5th workshop on Mathematically Structured Functional Programming. https://doi.org/10.4204/EPTCS.153.8
Google Scholar
Cross Ref
- Daan Leijen. 2017. Type Directed Compilation of Row-typed Algebraic Effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL’17). 486–499. isbn:978-1-4503-4660-3 https://doi.org/10.1145/3009837.3009872
Google Scholar
Digital Library
- Daan Leijen. 2018. First Class Dynamic Effect Handlers: Or, Polymorphic Heaps with Dynamic Effect Handlers. In Proceedings of the 3rd ACM SIGPLAN International Workshop on Type-Driven Development (TyDe 2018). 51–64.
Google Scholar
Digital Library
- Daan Leijen and Erik Meijer. 1999. Domain Specific Embedded Compilers. In In proceedings of the 2nd conference on domain specific languages. 109–122.
Google Scholar
- Sam Lindley, Connor McBride, and Craig McLaughlin. 2017. Do be do be do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL’17). 500–514. https://doi.org/10.1145/3009837.3009897
Google Scholar
Digital Library
- McCracken. 1984. The typechecking of programs with implicit type structure. In Lecture Notes in Computer Science (Semantics of Data Types, Vol. 173).
Google Scholar
- Simon L Peyton Jones and John Launchbury. 1995. State in Haskell. Lisp and Symbolic Comp., 8, 4 (1995), 293–341. https://doi.org/10.1007/BF01018827
Google Scholar
Digital Library
- 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 18th European Symposium on Programming Languages and Systems (ESOP’09). 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, https://doi.org/10.2168/LMCS-9(4:23)2013
Google Scholar
Cross Ref
- Matija Pretnar. 2010. Logic and handling of algebraic effects. Ph. D. Dissertation.
Google Scholar
- Matija Pretnar. 2015. An Introduction to Algebraic Effects and Handlers. Invited Tutorial Paper. Electron. Notes Theor. Comput. Sci., 319, C (2015), Dec., 19–35. issn:1571-0661 https://doi.org/10.1016/j.entcs.2015.12.003
Google Scholar
Digital Library
- Alex Reinking, Ningning Xie, Leonardo de Moura, and Daan Leijen. 2021. Perceus: Garbage Free Reference Counting with Reuse. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2021). Association for Computing Machinery, New York, NY, USA. 96–111. isbn:9781450383912 https://doi.org/10.1145/3453483.3454032
Google Scholar
Digital Library
- Taro Sekiyama and Atsushi Igarashi. 2019. Handling polymorphic algebraic effects. In European Symposium on Programming. 353–380.
Google Scholar
Cross Ref
- Miley Semmelroth and Amr Sabry. 1999. Monadic Encapsulation in ML. In Proceedings of the Fourth ACM SIGPLAN International Conference on Functional Programming (ICFP ’99). Association for Computing Machinery, New York, NY, USA. 8–17. isbn:1581131119 https://doi.org/10.1145/317636.317777
Google Scholar
Digital Library
- Chung-chieh Shan. 2007. A static simulation of dynamic delimited control. Higher-Order and Symbolic Computation, 20, 4 (2007), 371–401. issn:1573-0557 https://doi.org/10.1007/s10990-007-9010-4
Google Scholar
Digital Library
- Jesse Sigal. 2021. Automatic Differentiation via Effects and Handlers: An Implementation in Frank. In The ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM ’21).
Google Scholar
- Dorai Sitaram. 1993. Handling control. In Proceedings of the ACM SIGPLAN 1993 conference on Programming language design and implementation. 147–155.
Google Scholar
Digital Library
- Asumu Takikawa, T Stephen Strickland, and Sam Tobin-Hochstadt. 2013. Constraining delimited control with contracts. In European Symposium on Programming. 229–248.
Google Scholar
Digital Library
- Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, and Lars Birkedal. 2017. A Logical Relation for Monadic Encapsulation of State: Proving Contextual Equivalences in the Presence of RunST. Proc. ACM Program. Lang., 2, POPL (2017), Article 64, Dec., 28 pages. https://doi.org/10.1145/3158152
Google Scholar
Digital Library
- Mads Tofte and Jean-Pierre Talpin. 1997. Region-based memory management. Information and computation, 132, 2 (1997), 109–176.
Google Scholar
- Fei Wang, Daniel Zheng, James Decker, Xilun Wu, Grégory M Essertel, and Tiark Rompf. 2019. Demystifying differentiable programming: Shift/reset the penultimate backpropagator. Proceedings of the ACM on Programming Languages, 3, ICFP (2019), 1–31.
Google Scholar
Digital Library
- Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Inf. Comput., 115, 1 (1994), Nov., 38–94. https://doi.org/10.1006/inco.1994.1093
Google Scholar
Digital Library
- Nicolas Wu, Tom Schrijvers, and Ralf Hinze. 2014. Effect Handlers in Scope. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell (Haskell ’14). 1–12. isbn:978-1-4503-3041-1 https://doi.org/10.1145/2633357.2633358
Google Scholar
Digital Library
- Ningning Xie, Jonathan Brachthäuser, Phillip Schuster, Daniel Hillerström, and Daan Leijen. 2020. Effect Handlers, Evidently. In Proceedings of the 25th ACM SIGPLAN International Conference on Functional Programming (ICFP’2020) (ICFP ’20).
Google Scholar
- Ningning Xie, Youyou Cong, Kazuki Ikemori, and Daan Leijen. 2022. Artifact for "First-class Names for Effect Handlers". https://doi.org/10.5281/zenodo.7062933 Also available at <https://hub.docker.com/r/daanx/oopsla22-namedh>
Google Scholar
Digital Library
- Ningning Xie and Daan Leijen. 2020. Effect Handlers in Haskell, Evidently. In Proceedings of the 2020 ACM SIGPLAN Symposium on Haskell (Haskell’20).
Google Scholar
- 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, Article 71, 30 pages. 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), Jan., 29 pages. https://doi.org/10.1145/3290318
Google Scholar
Digital Library
Index Terms
First-class names for effect handlers
Recommendations
High-level effect handlers in C++
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 ...
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 ...
Liberating effects with rows and handlers
TyDe 2016: Proceedings of the 1st International Workshop on Type-Driven DevelopmentAlgebraic effects and effect handlers provide a modular abstraction for effectful programming. They support user-defined effects, as in Haskell, in conjunction with direct-style effectful programming, as in ML. They also present a structured interface ...






Comments