Abstract
Effect handlers can be composed by applying them sequentially, each handling some operations and leaving other operations uninterpreted in the syntax tree. However, the semantics of composed handlers can be subtle---it is well known that different orders of composing handlers can lead to drastically different semantics. Determining the correct order of composition is a non-trivial task.
To alleviate this problem, this paper presents a systematic way of deriving sufficient conditions on handlers for their composite to correctly handle combinations, such as the sum and the tensor, of the effect theories separately handled. These conditions are solely characterised by the clauses for relevant operations of the handlers, and are derived by fusing two handlers into one using a form of fold/build fusion and continuation-passing style transformation.
As case studies, the technique is applied to commutative and distributive interaction of handlers to obtain a series of results about the interaction of common handlers: (a) equations respected by each handler are preserved after handler composition; (b) handling mutable state before any handler gives rise to a semantics in which state operations are commutative with any operations from the latter handler; (c) handling the writer effect and mutable state in either order gives rise to a correct handler of the commutative combination of these two theories.
Supplemental Material
Available for Download
This contains the appendices to the paper Reasoning about Effect Interaction by Fusion accepted to ICFP 2021. The appendices contain detailed proofs of some of the lemmas and theorems in the paper.
- Danel Ahman. 2017. Handling Fibred Algebraic Effects. Proc. ACM Program. Lang., 2, POPL (2017), Article 7, Dec., 29 pages. https://doi.org/10.1145/3158095 Google Scholar
Digital Library
- Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? arxiv:1807.05923. arxiv:1807.05923Google Scholar
- Andrej Bauer and Matija Pretnar. 2014. An Effect System for Algebraic Effects and Handlers. Logical Methods in Computer Science, 10, 4 (2014), Dec, issn:1860-5974 https://doi.org/10.2168/lmcs-10(4:9)2014 Google Scholar
Cross Ref
- 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. issn:23522216 https://doi.org/10.1016/j.jlamp.2014.02.001 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 (2017), Article 8, Dec., 30 pages. https://doi.org/10.1145/3158096 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. Journal of Functional Programming, 30 (2020), e8. https://doi.org/10.1017/S0956796820000027 Google Scholar
Cross Ref
- Edwin Brady. 2013. Programming and Reasoning with Algebraic Effects and Dependent Types. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). Association for Computing Machinery, New York, NY, USA. 133–144. isbn:9781450323260 https://doi.org/10.1145/2500365.2500581 Google Scholar
Digital Library
- Joachim Breitner, Antal Spector-Zabusky, Yao Li, Christine Rizkallah, John Wiegley, and Stephanie Weirich. 2018. Ready, Set, Verify! Applying Hs-to-Coq to Real-World Haskell Code (Experience Report). Proc. ACM Program. Lang., 2, ICFP (2018), Article 89, July, 16 pages. https://doi.org/10.1145/3236784 Google Scholar
Digital Library
- Kwok-Ho Cheung. 2017. Distributive interaction of algebraic effects. Ph.D. Dissertation. University of Oxford.Google Scholar
- Andrzej Filinski. 1999. Representing Layered Monads. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’99). Association for Computing Machinery, New York, NY, USA. 175–188. isbn:1581130953 https://doi.org/10.1145/292540.292557 Google Scholar
Digital Library
- Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2017. On the Expressive Power of User-Defined Effects: Effect Handlers, Monadic Reflection, Delimited Control. Proc. ACM Program. Lang., 1, ICFP (2017), Article 13, Aug., 29 pages. https://doi.org/10.1145/3110257 Google Scholar
Digital Library
- Jeremy Gibbons and Ralf Hinze. 2011. Just do it: simple monadic equational reasoning. Proceeding of the 16th ACM SIGPLAN international conference on Functional programming - ICFP ’11, 2. issn:03621340 https://doi.org/10.1145/2034773.2034777 Google Scholar
Digital Library
- Andrew Gill, John Launchbury, and Simon L. Peyton Jones. 1993. A Short Cut to Deforestation. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture (FPCA ’93). Association for Computing Machinery, New York, NY, USA. 223–232. isbn:089791595X https://doi.org/10.1145/165180.165214 Google Scholar
Digital Library
- Daniel Hillerström and Sam Lindley. 2018. Shallow Effect Handlers. Lecture Notes in Computer Science, 11275 LNCS (2018), 415–435. isbn:9783030027674 issn:16113349 https://doi.org/10.1007/978-3-030-02768-1_22 Google Scholar
Cross Ref
- W. Hino, H. Kobayashi, I. Hasuo, and B. Jacobs. 2016. Healthiness from Duality. Proceedings - Symposium on Logic in Computer Science, 05-08-July (2016), 1–13. isbn:9781450343916 issn:10436871 https://doi.org/10.1145/2933575.2935319 arxiv:arXiv:1605.00381v1. Google Scholar
Digital Library
- Ralf Hinze. 2012. Kan Extensions for Program Optimisation Or: Art and Dan Explain an Old Trick. In Mathematics of Program Construction, Jeremy Gibbons and Pablo Nogueira (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 324–362. https://doi.org/978-3-642-31113-0_16Google Scholar
- Ralf Hinze, Thomas Harper, and Daniel W. H. James. 2011. Theory and Practice of Fusion. In Implementation and Application of Functional Languages, Jurriaan Hage and Marco T. Morazán (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 19–37. isbn:978-3-642-24276-2 https://doi.org/10.1007/978-3-642-24276-2_2 Google Scholar
Cross Ref
- C. A. R. Hoare. 1985. Communicating Sequential Processes. Prentice-Hall, Inc., USA. isbn:0131532715Google Scholar
Digital Library
- C. A. R. Hoare. 1985. A Couple of Novelties in the Propositional Calculus. Mathematical Logic Quarterly, 31, 9‐12 (1985), 173–178. https://doi.org/10.1002/malq.19850310905 Google Scholar
Cross Ref
- Martin Hyland, Gordon Plotkin, and John Power. 2006. Combining Effects: Sum and Tensor. Theor. Comput. Sci., 357, 1 (2006), July, 70–99. issn:0304-3975 https://doi.org/10.1016/j.tcs.2006.03.013 Google Scholar
Digital Library
- Bart Jacobs. 2017. A Recipe for State-and-Effect Triangles. Logical Methods in Computer Science, 13 (2017), 03, https://doi.org/10.23638/LMCS-13(2:6)2017 Google Scholar
Cross Ref
- Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in Action. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). Association for Computing Machinery, New York, NY, USA. 145–158. isbn:9781450323260 https://doi.org/10.1145/2500365.2500590 Google Scholar
Digital Library
- Oleg Kiselyov, Shin-cheng Mu, and Amr Sabry. 2021. Not by equations alone: Reasoning with extensible effects. Journal of Functional Programming, 31 (2021), e2. https://doi.org/10.1017/S0956796820000271 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 2017). Association for Computing Machinery, New York, NY, USA. 486–499. isbn:9781450346603 https://doi.org/10.1145/3009837.3009872 Google Scholar
Digital Library
- Žiga Lukšič and Matija Pretnar. 2020. Local algebraic effect theories. Journal of Functional Programming, 30 (2020), issn:1469-7653 https://doi.org/10.1017/s0956796819000212 Google Scholar
Cross Ref
- Saunders Mac Lane. 1998. Categories for the Working Mathematician, 2nd edn. Springer, Berlin. https://doi.org/10.1007/978-1-4757-4721-8 Google Scholar
Cross Ref
- Michael Mislove, Joël Ouaknine, and James Worrell. 2004. Axioms for Probability and Nondeterminism. Electronic Notes in Theoretical Computer Science, 96 (2004), 7 – 28. issn:1571-0661 https://doi.org/10.1016/j.entcs.2004.04.019 Proceedings of the 10th International Workshop on Expressiveness in Concurrency. Google Scholar
Cross Ref
- Eugenio Moggi. 1991. Notions of computation and monads. Information and Computation, 93, 1 (1991), 55 – 92. issn:0890-5401 https://doi.org/10.1016/0890-5401(91)90052-4 Selections from 1989 IEEE Symposium on Logic in Computer Science. Google Scholar
Digital Library
- Koen Pauwels, Tom Schrijvers, and Shin-Cheng Mu. 2019. Handling Local State with Global State. In Mathematics of Program Construction, Graham Hutton (Ed.). Springer International Publishing, Cham. 18–44. isbn:978-3-030-33636-3 https://doi.org/10.1007/978-3-030-33636-3_2 Google Scholar
Cross Ref
- Maciej Piróg, Tom Schrijvers, Nicolas Wu, and Mauro Jaskelioff. 2018. Syntax and semantics for operations with scopes. Proceedings - Symposium on Logic in Computer Science, 809–818. isbn:9781450355834 issn:10436871 https://doi.org/10.1145/3209108.3209166 Google Scholar
Digital Library
- Gordon Plotkin and John Power. 2002. Notions of Computation Determine Monads. In Foundations of Software Science and Computation Structures, Mogens Nielsen and Uffe Engberg (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 342–356. isbn:978-3-540-45931-6 https://doi.org/10.1007/3-540-45931-6_24 Google Scholar
Cross Ref
- Gordon Plotkin and John Power. 2003. Algebraic Operations and Generic Effects. Applied Categorical Structures, 11, 1 (2003), 69–94. issn:1572-9095 https://doi.org/10.1023/A:1023064908962 Google Scholar
Cross Ref
- Gordon Plotkin and John Power. 2004. Computational Effects and Operations: An Overview. Electr. Notes Theor. Comput. Sci., 73 (2004), 10, 149–163. https://doi.org/10.1016/j.entcs.2004.08.008 Google Scholar
Digital Library
- G. Plotkin and M. Pretnar. 2008. A Logic for Algebraic Effects. In 2008 23rd Annual IEEE Symposium on Logic in Computer Science. 118–129. https://doi.org/10.1109/LICS.2008.45 Google Scholar
Digital Library
- Gordon Plotkin and Matija Pretnar. 2009. Handlers of Algebraic Effects. In Programming Languages and Systems, Giuseppe Castagna (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 80–94. isbn:978-3-642-00590-9 https://doi.org/10.1007/978-3-642-00590-9_7 Google Scholar
Digital Library
- Gordon Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science, 9, 4 (2013), Dec, issn:1860-5974 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. University of Edinburgh, UK.Google Scholar
- Tom Schrijvers, Maciej Piróg, Nicolas Wu, and Mauro Jaskelioff. 2019. Monad Transformers and Modular Algebraic Effects: What Binds Them Together. In Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell (Haskell 2019). Association for Computing Machinery, New York, NY, USA. 98–113. isbn:9781450368131 https://doi.org/10.1145/3331545.3342595 Google Scholar
Digital Library
- Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2020. Compiling Effect Handlers in Capability-Passing Style. Proc. ACM Program. Lang., 4, ICFP (2020), Article 93, Aug., 28 pages. https://doi.org/10.1145/3408975 Google Scholar
Digital Library
- Willem Seynaeve, Koen Pauwels, and Tom Schrijvers. 2020. State Will do. In Trends in Functional Programming, Aleksander Byrski and John Hughes (Eds.). Springer International Publishing, Cham. 204–225. isbn:978-3-030-57761-2 https://doi.org/10.1007/978-3-030-57761-2_10 Google Scholar
Cross Ref
- Antal Spector-Zabusky, Joachim Breitner, Christine Rizkallah, and Stephanie Weirich. 2018. Total Haskell is Reasonable Coq. In Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP 2018). Association for Computing Machinery, New York, NY, USA. 14–27. isbn:9781450355865 https://doi.org/10.1145/3167092 Google Scholar
Digital Library
- Julien Tesson, Hideki Hashimoto, Zhenjiang Hu, Frédéric Loulergue, and Masato Takeichi. 2011. Program Calculation in Coq. In Algebraic Methodology and Software Technology, Michael Johnson and Dusko Pavlovic (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 163–179. isbn:978-3-642-17796-5 https://doi.org/10.1007/978-3-642-17796-5_10 Google Scholar
Cross Ref
- Niki Vazou, Joachim Breitner, Rose Kunkel, David Van Horn, and Graham Hutton. 2018. Theorem Proving for All: Equational Reasoning in Liquid Haskell (Functional Pearl). In Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell (Haskell 2018). Association for Computing Machinery, New York, NY, USA. 132–144. isbn:9781450358354 https://doi.org/10.1145/3242744.3242756 Google Scholar
Digital Library
- Niki Vazou, Anish Tondwalkar, Vikraman Choudhury, Ryan G. Scott, Ryan R. Newton, Philip Wadler, and Ranjit Jhala. 2017. Refinement Reflection: Complete Verification with SMT. Proc. ACM Program. Lang., 2, POPL (2017), Article 53, Dec., 31 pages. https://doi.org/10.1145/3158141 Google Scholar
Digital Library
- Janis Voigtländer. 2008. Asymptotic Improvement of Computations over Free Monads. In Mathematics of Program Construction, Philippe Audebaud and Christine Paulin-Mohring (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 388–403. isbn:978-3-540-70594-9 https://doi.org/10.1007/978-3-540-70594-9_20 Google Scholar
Digital Library
- Nicolas Wu and Tom Schrijvers. 2015. Fusion for Free. In Mathematics of Program Construction, Ralf Hinze and Janis Voigtländer (Eds.). Springer International Publishing, Cham. 302–322. https://doi.org/978-3-319-19797-5_15Google 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), Article 99, Aug., 29 pages. https://doi.org/10.1145/3408981 Google Scholar
Digital Library
- Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-Safe Effect Handlers via Tunneling. Proc. ACM Program. Lang., 3, POPL (2019), Article 5, Jan., 29 pages. https://doi.org/10.1145/3290318 Google Scholar
Digital Library
Index Terms
Reasoning about effect interaction by fusion
Recommendations
Effect handlers in scope
Haskell '14Algebraic effect handlers are a powerful means for describing effectful computations. They provide a lightweight and orthogonal technique to define and compose the syntax and semantics of different effects. The semantics is captured by handlers, which ...
Effect handlers in scope
Haskell '14: Proceedings of the 2014 ACM SIGPLAN symposium on HaskellAlgebraic effect handlers are a powerful means for describing effectful computations. They provide a lightweight and orthogonal technique to define and compose the syntax and semantics of different effects. The semantics is captured by handlers, which ...
An extensible dynamically-typed hierarchy of exceptions
Haskell '06: Proceedings of the 2006 ACM SIGPLAN workshop on HaskellIn this paper we address the lack of extensibility of the exception type in Haskell. We propose a lightweight solution involving the use of existential types and the Typeable class only, and show how our solution allows a fully extensible hierarchy of ...






Comments