Abstract
Handlers of algebraic effects aspire to be a practical and robust programming construct that allows one to define, use, and combine different computational effects. Interestingly, a critical problem that still bars the way to their popular adoption is how to combine different uses of the same effect in a program, particularly in a language with a static type-and-effect system. For example, it is rudimentary to define the “mutable memory cell” effect as a pair of operations, put and get, together with a handler, but it is far from obvious how to use this effect a number of times to operate a number of memory cells in a single context. In this paper, we propose a solution based on lexically scoped effects in which each use (an “instance”) of an effect can be singled out by name, bound by an enclosing handler and tracked in the type of the expression. Such a setting proves to be delicate with respect to the choice of semantics, as it depends on the explosive mixture of effects, polymorphism, and reduction under binders. Hence, we devise a novel approach to Kripke-style logical relations that can deal with open terms, which allows us to prove the desired properties of our calculus. We formalise our core results in Coq, and introduce an experimental surface-level programming language to show that our approach is applicable in practice.
Supplemental Material
- Amal Ahmed, Andrew W. Appel, Christopher D. Richards, Kedar N. Swadi, Gang Tan, and Daniel C. Wang. 2010. Semantic foundations for typed assembly languages. ACM Trans. Program. Lang. Syst. 32, 3 (2010), 7:1–7:67. 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, Savannah, GA, USA, January 21-23, 2009, Zhong Shao and Benjamin C. Pierce (Eds.). ACM, 340–353. 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. PACMPL 1, ICFP (2017), 39:1–39:28. 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), Peter Sestoft (Ed.), Vol. 3924. Springer, 69–83. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- Andrew W. Appel, Paul-André Melliès, Christopher D. Richards, and Jérôme Vouillon. 2007. A very modal model of a modern, major, general type system. In Proceedings of the 34th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2007, Nice, France, January 17-19, 2007. 109–122. Google Scholar
Digital Library
- Andrej Bauer and Matija Pretnar. 2014. An Effect System for Algebraic Effects and Handlers. Logical Methods in Computer Science 10, 4:9 (2014), 1–29. Google Scholar
Cross Ref
- Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. J. Log. Algebr. Meth. Program. 84, 1 (2015), 108–123. Google Scholar
Cross Ref
- Nick Benton and Andrew Kennedy. 2001. Exceptional Syntax. Journal of Functional Programming 11, 4 (2001), 395–410. Google Scholar
Digital Library
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2018. Handle with care: Relational interpretation of algebraic effects and handlers. PACMPL 2, POPL (2018), 8:1–8:30. Google Scholar
Digital Library
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting Algebraic Effects. PACMPL 3, POPL, Article 6 (2019), 28 pages. 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. 2018. Pyro: Deep Universal Probabilistic Programming. Journal of Machine Learning Research (2018).Google Scholar
- Lars Birkedal, Mads Tofte, and Magnus Vejlstrup. 1996. From Region Inference to von Neumann Machines via Region Representation Inference. In Conference Record of POPL’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, St. Petersburg Beach, Florida, USA, January 21-24, 1996, Hans-Juergen Boehm and Guy L. Steele Jr. (Eds.). ACM Press, 171–183. Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Effect handlers for the masses. PACMPL 2, OOPSLA (2018), 111:1–111:27. Google Scholar
Digital Library
- Edwin Brady. 2013. Programming and reasoning with algebraic effects and dependent types. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 133–144. Google Scholar
Digital Library
- Giuseppe Castagna and Andrew D. Gordon (Eds.). 2017. Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017. ACM. Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). 2011. Proceeding of the 16th ACM SIGPLAN International Conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011. ACM.Google Scholar
Digital Library
- Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2019. Doo bee doo bee doo. (2019). Draft.Google Scholar
- Dominique Devriese. 2019. Modular Effects in Haskell Through Effect Polymorphism and Explicit Dictionary Applications: A New Approach and the µVeriFast Verifier As a Case Study. In Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell (Haskell 2019). ACM, New York, NY, USA, 1–14. Google Scholar
Digital Library
- Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. 2015. Effective Concurrency through Algebraic Effects. (2015). OCaml Users and Developers Workshop, September 2015, Vancouver, Canada.Google Scholar
- Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2011. Logical Step-Indexed Logical Relations. Logical Methods in Computer Science 7, 2 (2011). Google Scholar
Cross Ref
- Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2017. On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control. PACMPL 1, ICFP (2017), 13:1–13:29. Google Scholar
Digital Library
- Pietro Di Gianantonio and Marino Miculan. 2002. A Unifying Approach to Recursive and Co-recursive Definitions. In Types for Proofs and Programs, Second International Workshop, TYPES 2002, Berg en Dal, The Netherlands, April 24-28, 2002, Selected Papers. 148–161. Google Scholar
Cross Ref
- Jeremy Gibbons and Ralf Hinze. 2011. Just do it: simple monadic equational reasoning, See [ Chakravarty et al. 2011 ], 2–14. Google Scholar
Digital Library
- Daniel Hillerström and Sam Lindley. 2016. Liberating effects with rows and handlers. In Proceedings of the 1st International Workshop on Type-Driven Development, [email protected] 2016, Nara, Japan, September 18, 2016, James Chapman and Wouter Swierstra (Eds.). ACM, 15–27. Google Scholar
Digital Library
- Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. J. Funct. Program. 27 (2017), e7. Google Scholar
Cross Ref
- Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In Proceedings 5th Workshop on Mathematically Structured Functional Programming, [email protected] 2014, Grenoble, France, 12 April 2014. 100–126. Google Scholar
Cross Ref
- Daan Leijen. 2017a. Implementing Algebraic Effects in C - "Monads for Free in C". In Programming Languages and Systems -15th Asian Symposium, APLAS 2017, Suzhou, China, November 27-29, 2017, Proceedings (Lecture Notes in Computer Science), Bor-Yuh Evan Chang (Ed.), Vol. 10695. Springer, 339–363. Google Scholar
Cross Ref
- Daan Leijen. 2017b. Structured asynchrony with algebraic effects. In Proceedings of the 2nd International Workshop on Type-Driven Development, [email protected] 2017, Oxford, UK, September 2017.Google Scholar
Digital Library
- Daan Leijen. 2017c. Type directed compilation of row-typed algebraic effects, See [ Castagna and Gordon 2017 ], 486–499. Google Scholar
Digital Library
- Daan Leijen. 2018. Algebraic Effect Handlers with Resources and Deep Finalization. Technical Report MSR-TR-2018-10. Microsoft Research.Google Scholar
- Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Inf. Comput. 185, 2 (2003), 182–210. Google Scholar
Digital Library
- Sheng Liang, Paul Hudak, and Mark P. Jones. 1995. Monad Transformers and Modular Interpreters. In Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, Ron K. Cytron and Peter Lee (Eds.). ACM Press, 333–343. Google Scholar
Digital Library
- Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do be do be do, See [ Castagna and Gordon 2017 ], 500–514. Google Scholar
Digital Library
- John M. Lucassen and David K. Gifford. 1988. Polymorphic Effect Systems. In Conference Record of the Fifteenth Annual ACM Symposium on Principles of Programming Languages, San Diego, California, USA, January 10-13, 1988. 47–57. Google Scholar
Digital Library
- Robin Milner, Mads Tofte, and David Macqueen. 1997. The Definition of Standard ML. MIT Press, Cambridge, MA, USA.Google Scholar
Digital Library
- Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput. 93, 1 (1991), 55–92. Google Scholar
Digital Library
- Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Typed Equivalence of Effect Handlers and Delimited Control. In 4th International Conference on Formal Structures for Computation and Deduction, FSCD 2019, June 24-30, 2019, Dortmund, Germany. (LIPIcs), Herman Geuvers (Ed.), Vol. 131. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 30:1–30:16. Google Scholar
Cross Ref
- Andrew Pitts and Ian Stark. 1998. Operational Reasoning for Functions with Local State. In Higher Order Operational Techniques in Semantics, Andrew Gordon and Andrew Pitts (Eds.). Publications of the Newton Institute, Cambridge University Press, 227–273. http://www.inf.ed.ac.uk/~stark/operfl.htmlGoogle Scholar
Digital Library
- Gordon D. Plotkin and A. John Power. 2004. Computational Effects and Operations: An Overview. Electronic Notes in Theoretical Computer Science 73 (2004), 149–163. Google Scholar
Digital Library
- Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science 9, 4:23 (2013), 1–36. Google Scholar
Cross Ref
- Matija Pretnar. 2015. An Introduction to Algebraic Effects and Handlers. Invited tutorial paper. Electr. Notes Theor. Comput. Sci. 319 (2015), 19–35. Google Scholar
Digital Library
- Tom Schrijvers and Bruno C. d. S. Oliveira. 2011. Monads, zippers and views: virtualizing the monad stack, See [ Chakravarty et al. 2011 ], 32–44. 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, Prague, Czech Republic, April 6-11, 2019, Proceedings (Lecture Notes in Computer Science), Luís Caires (Ed.), Vol. 11423. Springer, 353–380. Google Scholar
Cross Ref
- Mark Snyder and Perry Alexander. 2010. Monad Factory: Type-Indexed Monads. In Trends in Functional Programming - 11th International Symposium, TFP 2010, Norman, OK, USA, May 17-19, 2010. Revised Selected Papers (Lecture Notes in Computer Science), Rex L. Page, Zoltán Horváth, and Viktória Zsók (Eds.), Vol. 6546. Springer, 198–213. Google Scholar
Cross Ref
- Wouter Swierstra. 2008. Data types à la carte. J. Funct. Program. 18, 4 (2008), 423–436. Google Scholar
Digital Library
- Jean-Pierre Talpin and Pierre Jouvelot. 1994. The Type and Effect Discipline. Inf. Comput. 111, 2 (1994), 245–296. Google Scholar
Digital Library
- Matías Toro, Elizabeth Labrada, and Éric Tanter. 2019. Gradual parametricity, revisited. PACMPL 3, POPL (2019), 17:1–17:30. Google Scholar
Digital Library
- Philip Wadler. 1990. Comprehending Monads. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming (LFP ’90). ACM, 61–78. Google Scholar
Digital Library
- Philip Wadler. 1992. Monads for functional programming. In Proceedings of the Marktoberdorf Summer School on Program Design Calculi.Google Scholar
- Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe effect handlers via tunneling. PACMPL 3, POPL (2019), 5:1–5:29. Google Scholar
Digital Library
Index Terms
Binders by day, labels by night: effect instances via lexically scoped handlers
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 ...
Abstraction-safe effect handlers via tunneling
Algebraic effect handlers offer a unified approach to expressing control-flow transfer idioms such as exceptions, iteration, and async/await. Unfortunately, previous attempts to make these handlers type-safe have failed to support the fundamental ...
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