skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

Handle with care: relational interpretation of algebraic effects and handlers

Published:27 December 2017Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Danel Ahman. 2017. Handling fibred algebraic effects. https://danelahman.github.io/drafts/handling_fibred_algebraic_ effects.pdf Unpublished draft.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2014. Relative monads formalised. Journal of Formalized Reasoning 7, 1 (2014), 1–43. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Edwin Brady. 2013b. Programming and reasoning with algebraic effects and dependent types, See [ Morrisett and Uustalu 2013 ], 133–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2011. Logical step-indexed logical relations. Logical Methods in Computer Science 7, 2 (2011), 1–37. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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, [email protected] 2016, Nara, Japan, September 18, 2016, James Chapman and Wouter Swierstra (Eds.). ACM, 15–27. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in action, See [ Morrisett and Uustalu 2013 ], 145–158. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. Journal of Functional Programming 27 (2017), e7. Google ScholarGoogle ScholarCross RefCross Ref
  29. Shin-ya Katsumata. 2013. Relating computational effects by ⊤⊤-lifting. Information and Computation 222 (2013), 228–246. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Oleg Kiselyov and Kc Sivaramakrishnan. 2016. Eff directly in OCaml. (2016). ACM SIGPLAN Workshop on ML, September 2016, Nara, Japan.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Daan Leijen. 2014. Koka: Programming with row polymorphic effect types. In Proceedings of the 5th Workshop on Mathematically Structured Functional Programming, [email protected] 2014, Grenoble, France, 12 April 2014 (EPTCS), Paul Blain Levy and Neel Krishnaswami (Eds.), Vol. 153. 100–126. Google ScholarGoogle ScholarCross RefCross Ref
  34. Daan Leijen. 2017a. Structured asynchrony with algebraic effects. In Proceedings of the 2nd International Workshop on Type-Driven Development, [email protected] 2017, Oxford, UK, September 2017, Sam Lindley and Brent Yorgey (Eds.). ACM, 16–29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Daan Leijen. 2017b. Type directed compilation of row-typed algebraic effects, See [ Castagna and Gordon 2017 ], 486–499. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Paul Blain Levy. 2004. Call-By-Push-Value: A Functional/Imperative Synthesis. Semantics Structures in Computation, Vol. 2. Springer.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do be do be do, See [ Castagna and Gordon 2017 ], 500–514. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Eugenio Moggi. 1991. Notions of computation and monads. Information and Computation 93, 1 (1991), 55–92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. James H. Morris. 1968. Lambda Calculus Models of Programming Languages. Ph.D. Dissertation. Massachusets Institute of Technology.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  45. Gordon D. Plotkin and John Power. 2001b. Semantics for algebraic operations. Electronic Notes in Theoretical Computer Science 45 (2001), 332–345. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Gordon D. Plotkin and Matija Pretnar. 2013. Handling algebraic effects. Logical Methods in Computer Science 9, 4 (2013), 1–36. Google ScholarGoogle ScholarCross RefCross Ref
  49. Matija Pretnar. 2010. Logic and Handling of Algebraic Effects. Ph.D. Dissertation. University of Edinburgh, UK.Google ScholarGoogle Scholar
  50. Matija Pretnar. 2015. An introduction to algebraic effects and handlers. Invited tutorial paper. Electronic Notes in Theoretical Computer Science 319 (2015), 19–35. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

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

        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

        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!