Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Handle with care: relational interpretation of algebraic effects and handlers

Published: 27 December 2017 Publication History

Abstract

Algebraic effects and handlers have received a lot of attention recently, both from the theoretical point of view and in practical language design. This stems from the fact that algebraic effects give the programmer unprecedented freedom to define, combine, and interpret computational effects. This plenty-of-rope, however, demands not only a deep understanding of the underlying semantics, but also access to practical means of reasoning about effectful code, including correctness and program equivalence. In this paper we tackle this problem by constructing a step-indexed relational interpretation of a call-by-value calculus with algebraic effect handlers and a row-based polymorphic type-and-effect system. Our calculus, while striving for simplicity, enjoys desirable theoretical properties, and is close to the cores of programming languages with algebraic effects used in the wild, while the logical relation we build for it can be used to reason about non-trivial properties, such as contextual equivalence and contextual approximation of programs. Our development has been fully formalised in the Coq proof assistant.

Supplementary Material

Auxiliary Archive (popl18-p160-aux.zip)
Coq formalisation
WEBM File (handlewithcare.webm)

References

[1]
Samson Abramsky. 1990. The lazy lambda calculus. In Research Topics in Functional Programming, David A. Turner (Ed.). Addison-Wesley Longman Publishing Co., Inc., 65–116.
[2]
Danel Ahman. 2017. Handling fibred algebraic effects. https://danelahman.github.io/drafts/handling_fibred_algebraic_ effects.pdf Unpublished draft.
[3]
Danel Ahman, Neil Ghani, and Gordon D. Plotkin. 2016. Dependent types and fibred computational effects. In Foundations of Software Science and Computation Structures – 19th International Conference, FOSSACS 2016, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2016, Eindhoven, The Netherlands, April 2-8, 2016, Proceedings (Lecture Notes in Computer Science), Bart Jacobs and Christof Löding (Eds.), Vol. 9634. Springer, 36–54.
[4]
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.
[5]
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.
[6]
Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2014. Relative monads formalised. Journal of Formalized Reasoning 7, 1 (2014), 1–43.
[7]
Andrew W. Appel and David A. McAllester. 2001. An indexed model of recursive types for foundational proof-carrying code. ACM Transactions on Programming Languages and Systems 23, 5 (2001), 657–683.
[8]
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, Martin Hofmann and Matthias Felleisen (Eds.). ACM, 109–122.
[9]
Andrej Bauer and Matija Pretnar. 2014. An effect system for algebraic effects and handlers. Logical Methods in Computer Science 10, 4 (2014), 1–29.
[10]
Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. Journal of Logic and Algebraic Methods in Programming 84, 1 (2015), 108–123.
[11]
Nick Benton, Andrew Kennedy, Lennart Beringer, and Martin Hofmann. 2007. Relational semantics for effect-based program transformations with dynamic allocation. In Proceedings of the 9th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, July 14-16, 2007, Wrocław, Poland, Michael Leuschel and Andreas Podelski (Eds.). ACM, 87–96.
[12]
Małgorzata Biernacka, Dariusz Biernacki, and Olivier Danvy. 2005. An operational foundation for delimited continuations in the CPS hierarchy. Logical Methods in Computer Science 1, 2 (2005), 1–39.
[13]
Dariusz Biernacki and Sergueï Lenglet. 2012. Normal form bisimulations for delimited-control operators. In Functional and Logic Programming – 11th International Symposium, FLOPS 2012, Kobe, Japan, May 23-25, 2012. Proceedings (Lecture Notes in Computer Science), Tom Schrijvers and Peter Thiemann (Eds.), Vol. 7294. Springer, 47–61.
[14]
Dariusz Biernacki and Piotr Polesiuk. 2015. Logical relations for coherence of effect subtyping. In 13th International Conference on Typed Lambda Calculi and Applications, TLCA 2015, July 1-3, 2015, Warsaw, Poland (LIPIcs), Thorsten Altenkirch (Ed.), Vol. 38. Schloss Dagstuhl – Leibniz-Zentrum fuer Informatik, 107–122.
[15]
Edwin Brady. 2013a. Idris: general purpose programming with dependent types. In Proceedings of the 7th Workshop on Programming Languages meets Program Verification, PLPV 2013, Rome, Italy, January 22, 2013, Matthew Might, David Van Horn, Andreas Abel, and Tim Sheard (Eds.). ACM, 1–2.
[16]
Edwin Brady. 2013b. Programming and reasoning with algebraic effects and dependent types, See [ Morrisett and Uustalu 2013 ], 133–144.
[17]
Edwin Brady. 2014. Resource-dependent algebraic effects. In Trends in Functional Programming – 15th International Symposium, TFP 2014, Soesterberg, The Netherlands, May 26-28, 2014. Revised Selected Papers (Lecture Notes in Computer Science), Jurriaan Hage and Jay McCarthy (Eds.), Vol. 8843. Springer, 18–33.
[18]
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.
[19]
Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2011. Logical step-indexed logical relations. Logical Methods in Computer Science 7, 2 (2011), 1–37.
[20]
Derek Dreyer, Georg Neis, and Lars Birkedal. 2010. The impact of higher-order state and control effects on local relational reasoning. In Proceeding of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP 2010, Baltimore, Maryland, USA, September 27-29, 2010, Paul Hudak and Stephanie Weirich (Eds.). ACM, 143–156.
[21]
R. Kent Dybvig, Simon L. Peyton Jones, and Amr Sabry. 2007. A monadic framework for delimited continuations. Journal of Functional Programming 17, 6 (2007), 687–730.
[22]
Matthias Felleisen and Daniel P. Friedman. 1986. Control operators, the SECD machine, and the λ-calculus. In Formal Description of Programming Concepts III, Martin Wirsing (Ed.). Elsevier Science Publishers B.V. (North-Holland), 193–217.
[23]
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 (Lecture Notes in Computer Science), Herman Geuvers and Freek Wiedijk (Eds.), Vol. 2646. Springer, 148–161.
[24]
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@ICFP 2016, Nara, Japan, September 18, 2016, James Chapman and Wouter Swierstra (Eds.). ACM, 15–27.
[25]
Daniel Hillerström, Sam Lindley, Robert Atkey, and K. C. Sivaramakrishnan. 2017. Continuation passing style for effect handlers. In 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017, September 3-9, 2017, Oxford, UK (LIPIcs), Dale Miller (Ed.), Vol. 84. Schloss Dagstuhl – Leibniz-Zentrum fuer Informatik, 18:1–18:19.
[26]
Martin Hyland and John Power. 2007. The category theoretic understanding of universal algebra: Lawvere theories and monads. Electronic Notes in Theoretical Computer Science 172 (2007), 437–458.
[27]
Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in action, See [ Morrisett and Uustalu 2013 ], 145–158.
[28]
Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. Journal of Functional Programming 27 (2017), e7.
[29]
Shin-ya Katsumata. 2013. Relating computational effects by ⊤⊤-lifting. Information and Computation 222 (2013), 228–246.
[30]
Oleg Kiselyov, Amr Sabry, and Cameron Swords. 2013. Extensible effects: an alternative to monad transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Boston, MA, USA, September 23-24, 2013, Chung-chieh Shan (Ed.). ACM, 59–70.
[31]
Oleg Kiselyov and Kc Sivaramakrishnan. 2016. Eff directly in OCaml. (2016). ACM SIGPLAN Workshop on ML, September 2016, Nara, Japan.
[32]
Søren B. Lassen. 2005. Eager normal form bisimulation. In 20th IEEE Symposium on Logic in Computer Science (LICS 2005), 26-29 June 2005, Chicago, IL, USA, Proceedings, Prakash Panangaden (Ed.). IEEE Computer Society, 345–354.
[33]
Daan Leijen. 2014. Koka: Programming with row polymorphic effect types. In Proceedings of the 5th Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2014, Grenoble, France, 12 April 2014 (EPTCS), Paul Blain Levy and Neel Krishnaswami (Eds.), Vol. 153. 100–126.
[34]
Daan Leijen. 2017a. Structured asynchrony with algebraic effects. In Proceedings of the 2nd International Workshop on Type-Driven Development, TyDe@ICFP 2017, Oxford, UK, September 2017, Sam Lindley and Brent Yorgey (Eds.). ACM, 16–29.
[35]
Daan Leijen. 2017b. Type directed compilation of row-typed algebraic effects, See [ Castagna and Gordon 2017 ], 486–499.
[36]
Paul Blain Levy. 2004. Call-By-Push-Value: A Functional/Imperative Synthesis. Semantics Structures in Computation, Vol. 2. Springer.
[37]
Sam Lindley. 2014. Algebraic effects and effect handlers for idioms and arrows. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming, WGP 2014, Gothenburg, Sweden, August 31, 2014, José Pedro Magalhães and Tiark Rompf (Eds.). ACM, 47–58.
[38]
Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do be do be do, See [ Castagna and Gordon 2017 ], 500–514.
[39]
Eugenio Moggi. 1991. Notions of computation and monads. Information and Computation 93, 1 (1991), 55–92.
[40]
James H. Morris. 1968. Lambda Calculus Models of Programming Languages. Ph.D. Dissertation. Massachusets Institute of Technology.
[41]
Greg Morrisett and Tarmo Uustalu (Eds.). 2013. ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA – September 25 - 27, 2013. ACM.
[42]
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.
[43]
Gordon D. Plotkin and A. John Power. 2004. Computational effects and operations: An overview. Electronic Notes in Theoretical Computer Science 73 (2004), 149–163.
[44]
Gordon D. Plotkin and John Power. 2001a. Adequacy for algebraic effects. In Foundations of Software Science and Computation Structures, 4th International Conference, FOSSACS 2001, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2001 Genova, Italy, April 2-6, 2001, Proceedings (Lecture Notes in Computer Science), Furio Honsell and Marino Miculan (Eds.), Vol. 2030. Springer, 1–24.
[45]
Gordon D. Plotkin and John Power. 2001b. Semantics for algebraic operations. Electronic Notes in Theoretical Computer Science 45 (2001), 332–345.
[46]
Gordon D. Plotkin and John Power. 2002. Notions of computation determine monads. In Foundations of Software Science and Computation Structures, 5th International Conference, FOSSACS 2002, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2002 Grenoble, France, April 8-12, 2002, Proceedings (Lecture Notes in Computer Science), Mogens Nielsen and Uffe Engberg (Eds.), Vol. 2303. Springer, 342–356.
[47]
Gordon D. Plotkin and Matija Pretnar. 2008. A logic for algebraic effects. In Proceedings of the Twenty-Third Annual IEEE Symposium on Logic in Computer Science, LICS 2008, 24-27 June 2008, Pittsburgh, PA, USA. IEEE Computer Society, 118–129.
[48]
Gordon D. Plotkin and Matija Pretnar. 2013. Handling algebraic effects. Logical Methods in Computer Science 9, 4 (2013), 1–36.
[49]
Matija Pretnar. 2010. Logic and Handling of Algebraic Effects. Ph.D. Dissertation. University of Edinburgh, UK.
[50]
Matija Pretnar. 2015. An introduction to algebraic effects and handlers. Invited tutorial paper. Electronic Notes in Theoretical Computer Science 319 (2015), 19–35.
[51]
Didier Rémy. 1994. Type inference for records in natural extension of ML. In Theoretical Aspects of Object-Oriented Programming, Carl A. Gunter and John C. Mitchell (Eds.). MIT Press, 67–95.
[52]
John C. Reynolds. 1983. Types, abstraction and parametric polymorphism. In Information Processing 83, Proceedings of the IFIP 9th World Computer Congress, Paris, France, September 19-23, 1983, R. E. A. Mason (Ed.). North-Holland/IFIP, 513–523.
[53]
Davide Sangiorgi, Naoki Kobayashi, and Eijiro Sumii. 2011. Environmental bisimulations for higher-order languages. ACM Transactions on Programming Languages and Systems 33, 1 (2011), 5:1–5:69.
[54]
Tom Schrijvers, Nicolas Wu, Benoit Desouter, and Bart Demoen. 2014. Heuristics entwined with handlers combined: From functional specification to logic programming implementation. In Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming, Kent, Canterbury, United Kingdom, September 8-10, 2014, Olaf Chitil, Andy King, and Olivier Danvy (Eds.). ACM, 259–270.
[55]
Jacob Thamsborg and Lars Birkedal. 2011. A Kripke logical relation for effect-based program transformations. In Proceeding of the 16th ACM SIGPLAN International Conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011, Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). ACM, 445–456.
[56]
Nicolas Wu and Tom Schrijvers. 2015. Fusion for free – efficient algebraic effect handlers. In Mathematics of Program Construction – 12th International Conference, MPC 2015, Königswinter, Germany, June 29 - July 1, 2015. Proceedings (Lecture Notes in Computer Science), Ralf Hinze and Janis Voigtländer (Eds.), Vol. 9129. Springer, 302–322.

Cited By

View all
  • (2024)Abstracting Effect Systems for Algebraic Effect HandlersProceedings of the ACM on Programming Languages10.1145/36746418:ICFP(455-484)Online publication date: 15-Aug-2024
  • (2024)Effectful Software ContractsProceedings of the ACM on Programming Languages10.1145/36329308:POPL(2639-2666)Online publication date: 5-Jan-2024
  • (2024)Algebraic Effects Meet Hoare Logic in Cubical AgdaProceedings of the ACM on Programming Languages10.1145/36328988:POPL(1663-1695)Online publication date: 5-Jan-2024
  • Show More Cited By

Index Terms

  1. Handle with care: relational interpretation of algebraic effects and handlers

        Recommendations

        Comments

        Information & Contributors

        Information

        Published In

        cover image Proceedings of the ACM on Programming Languages
        Proceedings of the ACM on Programming Languages  Volume 2, Issue POPL
        January 2018
        1961 pages
        EISSN:2475-1421
        DOI:10.1145/3177123
        Issue’s Table of Contents
        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        Published: 27 December 2017
        Published in PACMPL Volume 2, Issue POPL

        Permissions

        Request permissions for this article.

        Check for updates

        Badges

        Author Tags

        1. algebraic effect
        2. logical relation
        3. row polymorphism

        Qualifiers

        • Research-article

        Contributors

        Other Metrics

        Bibliometrics & Citations

        Bibliometrics

        Article Metrics

        • Downloads (Last 12 months)175
        • Downloads (Last 6 weeks)27
        Reflects downloads up to 21 Sep 2024

        Other Metrics

        Citations

        Cited By

        View all
        • (2024)Abstracting Effect Systems for Algebraic Effect HandlersProceedings of the ACM on Programming Languages10.1145/36746418:ICFP(455-484)Online publication date: 15-Aug-2024
        • (2024)Effectful Software ContractsProceedings of the ACM on Programming Languages10.1145/36329308:POPL(2639-2666)Online publication date: 5-Jan-2024
        • (2024)Algebraic Effects Meet Hoare Logic in Cubical AgdaProceedings of the ACM on Programming Languages10.1145/36328988:POPL(1663-1695)Online publication date: 5-Jan-2024
        • (2024)Term Evaluation Systems with Refinements: First-Order, Second-Order, and Contextual ImprovementFunctional and Logic Programming10.1007/978-981-97-2300-3_3(31-61)Online publication date: 15-May-2024
        • (2023)From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersProceedings of the ACM on Programming Languages10.1145/36228317:OOPSLA2(941-970)Online publication date: 16-Oct-2023
        • (2023)A General Fine-Grained Reduction Theory for Effect HandlersProceedings of the ACM on Programming Languages10.1145/36078487:ICFP(511-540)Online publication date: 31-Aug-2023
        • (2023)PRADA: Practical Black-box Adversarial Attacks against Neural Ranking ModelsACM Transactions on Information Systems10.1145/357692341:4(1-27)Online publication date: 8-Apr-2023
        • (2023)Hefty Algebras: Modular Elaboration of Higher-Order Algebraic EffectsProceedings of the ACM on Programming Languages10.1145/35712557:POPL(1801-1831)Online publication date: 11-Jan-2023
        • (2023)A Type System for Effect Handlers and Dynamic LabelsProgramming Languages and Systems10.1007/978-3-031-30044-8_9(225-252)Online publication date: 22-Apr-2023
        • (2022)Indexing the extended Dyck-CFL reachability for context-sensitive program analysisProceedings of the ACM on Programming Languages10.1145/35633396:OOPSLA2(1438-1468)Online publication date: 31-Oct-2022
        • Show More Cited By

        View Options

        View options

        PDF

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader

        Get Access

        Login options

        Full Access

        Media

        Figures

        Other

        Tables

        Share

        Share

        Share this Publication link

        Share on social media