Nothing Special   »   [go: up one dir, main page]

skip to main content
research-article
Open access

Reasoning about effect interaction by fusion

Published: 19 August 2021 Publication History

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.

Supplementary Material

Auxiliary Archive (icfp21main-p61-p-archive.zip)
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.
Auxiliary Presentation Video (icfp21main-p61-p-video.mp4)
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.
MP4 File (3473578.mp4)
Presentation Videos

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
[2]
Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? arxiv:1807.05923. arxiv:1807.05923
[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
[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
[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
[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
[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
[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
[9]
Kwok-Ho Cheung. 2017. Distributive interaction of algebraic effects. Ph.D. Dissertation. University of Oxford.
[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
[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
[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
[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
[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
[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.
[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_16
[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
[18]
C. A. R. Hoare. 1985. Communicating Sequential Processes. Prentice-Hall, Inc., USA. isbn:0131532715
[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
[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
[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
[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
[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
[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
[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
[26]
Saunders Mac Lane. 1998. Categories for the Working Mathematician, 2nd edn. Springer, Berlin. https://doi.org/10.1007/978-1-4757-4721-8
[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.
[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.
[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
[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
[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
[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
[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
[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
[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
[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
[37]
Matija Pretnar. 2010. Logic and handling of algebraic effects. Ph.D. Dissertation. University of Edinburgh, UK.
[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
[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
[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
[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
[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
[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
[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
[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
[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_15
[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
[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

Cited By

View all
  • (2024)Making a Curry Interpreter using Effects and HandlersProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678279(68-82)Online publication date: 29-Aug-2024
  • (2024)Competitive Online Path-Aware Path SelectionACM SIGMETRICS Performance Evaluation Review10.1145/3649477.364949851:4(66-72)Online publication date: 23-Feb-2024
  • (2024)Modular Denotational Semantics for Effects with Guarded Interaction TreesProceedings of the ACM on Programming Languages10.1145/36328548:POPL(332-361)Online publication date: 5-Jan-2024
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

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
This work is licensed under a Creative Commons Attribution International 4.0 License.

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 for this article.

Check for updates

Author Tags

  1. CPS transformation
  2. Haskell
  3. fusion
  4. modular handlers

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)177
  • Downloads (Last 6 weeks)22
Reflects downloads up to 10 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Making a Curry Interpreter using Effects and HandlersProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678279(68-82)Online publication date: 29-Aug-2024
  • (2024)Competitive Online Path-Aware Path SelectionACM SIGMETRICS Performance Evaluation Review10.1145/3649477.364949851:4(66-72)Online publication date: 23-Feb-2024
  • (2024)Modular Denotational Semantics for Effects with Guarded Interaction TreesProceedings of the ACM on Programming Languages10.1145/36328548:POPL(332-361)Online publication date: 5-Jan-2024
  • (2024)A framework for higher-order effects & handlersScience of Computer Programming10.1016/j.scico.2024.103086234:COnline publication date: 25-Jun-2024
  • (2023)Trade-off Analysis in Learning-augmented Algorithms with Societal Design CriteriaACM SIGMETRICS Performance Evaluation Review10.1145/3626570.362659051:2(53-58)Online publication date: 2-Oct-2023
  • (2023)Modular Models of Monoids with OperationsProceedings of the ACM on Programming Languages10.1145/36078507:ICFP(566-603)Online publication date: 31-Aug-2023
  • (2023)Involving Teachers in the Data-Driven Improvement of Intelligent Tutors: A Prototyping StudyArtificial Intelligence in Education10.1007/978-3-031-36272-9_28(340-352)Online publication date: 3-Jul-2023
  • (2022)Mitigating silent data corruptions in HPC applications across multiple program inputsProceedings of the International Conference on High Performance Computing, Networking, Storage and Analysis10.5555/3571885.3571907(1-14)Online publication date: 13-Nov-2022
  • (2022)The Online Knapsack Problem with DeparturesProceedings of the ACM on Measurement and Analysis of Computing Systems10.1145/35706186:3(1-32)Online publication date: 8-Dec-2022
  • (2022)Competitive Algorithms for Online Multidimensional Knapsack ProblemsACM SIGMETRICS Performance Evaluation Review10.1145/3547353.352262750:1(87-88)Online publication date: 7-Jul-2022
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media