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

Binders by day, labels by night: effect instances via lexically scoped handlers

Published:20 December 2019Publication History
Skip Abstract Section

Abstract

Handlers of algebraic effects aspire to be a practical and robust programming construct that allows one to define, use, and combine different computational effects. Interestingly, a critical problem that still bars the way to their popular adoption is how to combine different uses of the same effect in a program, particularly in a language with a static type-and-effect system. For example, it is rudimentary to define the “mutable memory cell” effect as a pair of operations, put and get, together with a handler, but it is far from obvious how to use this effect a number of times to operate a number of memory cells in a single context. In this paper, we propose a solution based on lexically scoped effects in which each use (an “instance”) of an effect can be singled out by name, bound by an enclosing handler and tracked in the type of the expression. Such a setting proves to be delicate with respect to the choice of semantics, as it depends on the explosive mixture of effects, polymorphism, and reduction under binders. Hence, we devise a novel approach to Kripke-style logical relations that can deal with open terms, which allows us to prove the desired properties of our calculus. We formalise our core results in Coq, and introduce an experimental surface-level programming language to show that our approach is applicable in practice.

Skip Supplemental Material Section

Supplemental Material

a48-biernacki.webm

References

  1. Amal Ahmed, Andrew W. Appel, Christopher D. Richards, Kedar N. Swadi, Gang Tan, and Daniel C. Wang. 2010. Semantic foundations for typed assembly languages. ACM Trans. Program. Lang. Syst. 32, 3 (2010), 7:1–7:67. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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
  3. Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for free for free: parametricity, with and without types. PACMPL 1, ICFP (2017), 39:1–39:28. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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
  5. Andrew W. Appel and David A. McAllester. 2001. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. Program. Lang. Syst. 23, 5 (2001), 657–683. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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. 109–122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Andrej Bauer and Matija Pretnar. 2014. An Effect System for Algebraic Effects and Handlers. Logical Methods in Computer Science 10, 4:9 (2014), 1–29. Google ScholarGoogle ScholarCross RefCross Ref
  8. Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. J. Log. Algebr. Meth. Program. 84, 1 (2015), 108–123. Google ScholarGoogle ScholarCross RefCross Ref
  9. Nick Benton and Andrew Kennedy. 2001. Exceptional Syntax. Journal of Functional Programming 11, 4 (2001), 395–410. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2018. Handle with care: Relational interpretation of algebraic effects and handlers. PACMPL 2, POPL (2018), 8:1–8:30. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting Algebraic Effects. PACMPL 3, POPL, Article 6 (2019), 28 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul Szerlip, Paul Horsfall, and Noah D. Goodman. 2018. Pyro: Deep Universal Probabilistic Programming. Journal of Machine Learning Research (2018).Google ScholarGoogle Scholar
  13. Lars Birkedal, Mads Tofte, and Magnus Vejlstrup. 1996. From Region Inference to von Neumann Machines via Region Representation Inference. In Conference Record of POPL’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, St. Petersburg Beach, Florida, USA, January 21-24, 1996, Hans-Juergen Boehm and Guy L. Steele Jr. (Eds.). ACM Press, 171–183. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Effect handlers for the masses. PACMPL 2, OOPSLA (2018), 111:1–111:27. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Edwin Brady. 2013. Programming and reasoning with algebraic effects and dependent types. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 133–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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
  17. Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). 2011. Proceeding of the 16th ACM SIGPLAN International Conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011. ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2019. Doo bee doo bee doo. (2019). Draft.Google ScholarGoogle Scholar
  19. Dominique Devriese. 2019. Modular Effects in Haskell Through Effect Polymorphism and Explicit Dictionary Applications: A New Approach and the µVeriFast Verifier As a Case Study. In Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell (Haskell 2019). ACM, New York, NY, USA, 1–14. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. 2015. Effective Concurrency through Algebraic Effects. (2015). OCaml Users and Developers Workshop, September 2015, Vancouver, Canada.Google ScholarGoogle Scholar
  21. Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2011. Logical Step-Indexed Logical Relations. Logical Methods in Computer Science 7, 2 (2011). Google ScholarGoogle ScholarCross RefCross Ref
  22. Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2017. On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control. PACMPL 1, ICFP (2017), 13:1–13:29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. 148–161. Google ScholarGoogle ScholarCross RefCross Ref
  24. Jeremy Gibbons and Ralf Hinze. 2011. Just do it: simple monadic equational reasoning, See [ Chakravarty et al. 2011 ], 2–14. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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
  26. Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. J. Funct. Program. 27 (2017), e7. Google ScholarGoogle ScholarCross RefCross Ref
  27. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In Proceedings 5th Workshop on Mathematically Structured Functional Programming, [email protected] 2014, Grenoble, France, 12 April 2014. 100–126. Google ScholarGoogle ScholarCross RefCross Ref
  28. Daan Leijen. 2017a. Implementing Algebraic Effects in C - "Monads for Free in C". In Programming Languages and Systems -15th Asian Symposium, APLAS 2017, Suzhou, China, November 27-29, 2017, Proceedings (Lecture Notes in Computer Science), Bor-Yuh Evan Chang (Ed.), Vol. 10695. Springer, 339–363. Google ScholarGoogle ScholarCross RefCross Ref
  29. Daan Leijen. 2017b. Structured asynchrony with algebraic effects. In Proceedings of the 2nd International Workshop on Type-Driven Development, [email protected] 2017, Oxford, UK, September 2017.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Daan Leijen. 2017c. Type directed compilation of row-typed algebraic effects, See [ Castagna and Gordon 2017 ], 486–499. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Daan Leijen. 2018. Algebraic Effect Handlers with Resources and Deep Finalization. Technical Report MSR-TR-2018-10. Microsoft Research.Google ScholarGoogle Scholar
  32. Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Inf. Comput. 185, 2 (2003), 182–210. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Sheng Liang, Paul Hudak, and Mark P. Jones. 1995. Monad Transformers and Modular Interpreters. In Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, Ron K. Cytron and Peter Lee (Eds.). ACM Press, 333–343. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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
  35. John M. Lucassen and David K. Gifford. 1988. Polymorphic Effect Systems. In Conference Record of the Fifteenth Annual ACM Symposium on Principles of Programming Languages, San Diego, California, USA, January 10-13, 1988. 47–57. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Robin Milner, Mads Tofte, and David Macqueen. 1997. The Definition of Standard ML. MIT Press, Cambridge, MA, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput. 93, 1 (1991), 55–92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Typed Equivalence of Effect Handlers and Delimited Control. In 4th International Conference on Formal Structures for Computation and Deduction, FSCD 2019, June 24-30, 2019, Dortmund, Germany. (LIPIcs), Herman Geuvers (Ed.), Vol. 131. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 30:1–30:16. Google ScholarGoogle ScholarCross RefCross Ref
  39. 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. http://www.inf.ed.ac.uk/~stark/operfl.htmlGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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
  41. Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science 9, 4:23 (2013), 1–36. Google ScholarGoogle ScholarCross RefCross Ref
  42. Matija Pretnar. 2015. An Introduction to Algebraic Effects and Handlers. Invited tutorial paper. Electr. Notes Theor. Comput. Sci. 319 (2015), 19–35. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Tom Schrijvers and Bruno C. d. S. Oliveira. 2011. Monads, zippers and views: virtualizing the monad stack, See [ Chakravarty et al. 2011 ], 32–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Taro Sekiyama and Atsushi Igarashi. 2019. Handling Polymorphic Algebraic Effects. In Programming Languages and Systems - 28th European Symposium on Programming, ESOP 2019, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2019, Prague, Czech Republic, April 6-11, 2019, Proceedings (Lecture Notes in Computer Science), Luís Caires (Ed.), Vol. 11423. Springer, 353–380. Google ScholarGoogle ScholarCross RefCross Ref
  45. Mark Snyder and Perry Alexander. 2010. Monad Factory: Type-Indexed Monads. In Trends in Functional Programming - 11th International Symposium, TFP 2010, Norman, OK, USA, May 17-19, 2010. Revised Selected Papers (Lecture Notes in Computer Science), Rex L. Page, Zoltán Horváth, and Viktória Zsók (Eds.), Vol. 6546. Springer, 198–213. Google ScholarGoogle ScholarCross RefCross Ref
  46. Wouter Swierstra. 2008. Data types à la carte. J. Funct. Program. 18, 4 (2008), 423–436. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Jean-Pierre Talpin and Pierre Jouvelot. 1994. The Type and Effect Discipline. Inf. Comput. 111, 2 (1994), 245–296. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Matías Toro, Elizabeth Labrada, and Éric Tanter. 2019. Gradual parametricity, revisited. PACMPL 3, POPL (2019), 17:1–17:30. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Philip Wadler. 1990. Comprehending Monads. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming (LFP ’90). ACM, 61–78. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Philip Wadler. 1992. Monads for functional programming. In Proceedings of the Marktoberdorf Summer School on Program Design Calculi.Google ScholarGoogle Scholar
  51. Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe effect handlers via tunneling. PACMPL 3, POPL (2019), 5:1–5:29. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Binders by day, labels by night: effect instances via lexically scoped 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!