skip to main content
research-article
Open Access

Reasoning about effect interaction by fusion

Published:19 August 2021Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

3473578.mp4

Presentation Videos

Auxiliary Presentation Video

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? arxiv:1807.05923. arxiv:1807.05923Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarCross RefCross Ref
  4. 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 ScholarGoogle ScholarCross RefCross Ref
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarCross RefCross Ref
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Kwok-Ho Cheung. 2017. Distributive interaction of algebraic effects. Ph.D. Dissertation. University of Oxford.Google ScholarGoogle Scholar
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarCross RefCross Ref
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarCross RefCross Ref
  18. C. A. R. Hoare. 1985. Communicating Sequential Processes. Prentice-Hall, Inc., USA. isbn:0131532715Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarCross RefCross Ref
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarCross RefCross Ref
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarCross RefCross Ref
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. Ž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 ScholarGoogle ScholarCross RefCross Ref
  26. Saunders Mac Lane. 1998. Categories for the Working Mathematician, 2nd edn. Springer, Berlin. https://doi.org/10.1007/978-1-4757-4721-8 Google ScholarGoogle ScholarCross RefCross Ref
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarCross RefCross Ref
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarCross RefCross Ref
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarCross RefCross Ref
  37. Matija Pretnar. 2010. Logic and handling of algebraic effects. Ph.D. Dissertation. University of Edinburgh, UK.Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarCross RefCross Ref
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarCross RefCross Ref
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  46. 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 ScholarGoogle Scholar
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Reasoning about effect interaction by fusion

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image Proceedings of the ACM on Programming Languages
        Proceedings of the ACM on Programming Languages  Volume 5, Issue ICFP
        August 2021
        1011 pages
        EISSN:2475-1421
        DOI:10.1145/3482883
        Issue’s Table of Contents

        Copyright © 2021 Owner/Author

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 19 August 2021
        Published in pacmpl Volume 5, Issue ICFP

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!