skip to main content
research-article
Open Access

Effect handlers, evidently

Published:03 August 2020Publication History
Skip Abstract Section

Abstract

Algebraic effect handlers are a powerful way to incorporate effects in a programming language. Sometimes perhaps even _too_ powerful. In this article we define a restriction of general effect handlers with _scoped resumptions_. We argue one can still express all important effects, while improving reasoning about effect handlers. Using the newly gained guarantees, we define a sound and coherent evidence translation for effect handlers, which directly passes the handlers as evidence to each operation. We prove full soundness and coherence of the translation into plain lambda calculus. The evidence in turn enables efficient implementations of effect operations; in particular, we show we can execute tail-resumptive operations _in place_ (without needing to capture the evaluation context), and how we can replace the runtime search for a handler by indexing with a constant offset.

Skip Supplemental Material Section

Supplemental Material

Presentation at ICFP '20

References

  1. Arthur I. Baars, and S. Doaitse Swierstra. 2002. Typing Dynamic Typing. In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, 157-166. ICFP' 02. Pittsburgh, PA, USA. doi: 10.1145/581478.581494.Google ScholarGoogle Scholar
  2. Andrej Bauer, and Matija Pretnar. 2014. An Efect System for Algebraic Efects and Handlers. Logical Methods in Computer Science 10 ( 4 ).Google ScholarGoogle Scholar
  3. Andrej Bauer, and Matija Pretnar. 2015a. Programming with Algebraic Efects and Handlers. Journal of Logical and Algebraic Methods in Programming 84 ( 1 ). Elsevier: 108-123.Google ScholarGoogle ScholarCross RefCross Ref
  4. Andrej Bauer, and Matija Pretnar. 2015b. Programming with Algebraic Efects and Handlers. J. Log. Algebr. Meth. Program. 84 ( 1 ): 108-123. doi: 10.1016/j.jlamp. 2014. 02.001.Google ScholarGoogle ScholarCross RefCross Ref
  5. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. Dec. 2017. Handle with Care: Relational Interpretation of Algebraic Efects and Handlers. Proc. ACM Program. Lang. 2 ( POPL '17 issue): 8 : 1-8 : 30. doi: 10.1145/3158096.Google ScholarGoogle Scholar
  6. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. Dec. 2019. Binders by Day, Labels by Night: Efect Instances via Lexically Scoped Handlers. Proc. ACM Program. Lang. 4 ( POPL ). Association for Computing Machinery, New York, NY, USA. doi: 10.1145/3371116.Google ScholarGoogle Scholar
  7. Jonathan Immanuel Brachthäuser, and Philipp Schuster. Oct. 2017. Efekt: Extensible Algebraic Efects in Scala. In Scala' 17. Vancouver, CA.Google ScholarGoogle Scholar
  8. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. Oct. 2018. Efect Handlers for the Masses. Proc. ACM Program. Lang. 2 ( OOPSLA ). Association for Computing Machinery, New York, NY, USA. doi: 10.1145/3276481.Google ScholarGoogle Scholar
  9. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Efekt: Lightweight Efect Polymorphism for Handlers. Technical Report. University of Tübingen, Germany.Google ScholarGoogle Scholar
  10. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Efekt: Capability-Passing Style for Typeand Efect-Safe, Extensible Efect Handlers in Scala. Journal of Functional Programming. Cambridge University Press.Google ScholarGoogle Scholar
  11. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. May 2017. Concurrent System Programming with Efect Handlers. In Proceedings of the Symposium on Trends in Functional Programming. TFP'17.Google ScholarGoogle Scholar
  12. Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. Sep. 2015. Efective Concurrency through Algebraic Efects. In OCaml Workshop.Google ScholarGoogle Scholar
  13. R Kent Dyvbig, Simon Peyton Jones, and Amr Sabry. 2007. A Monadic Framework for Delimited Continuations. Journal of Functional Programming 17 ( 6 ). Cambridge University Press: 687-730. doi: 10.1017/S0956796807006259.Google ScholarGoogle Scholar
  14. Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2019. On the Expressive Power of User-Defined Efects: Efect Handlers, Monadic Reflection, Delimited Control. Journal of Functional Programming 29. Cambridge University Press: 15. doi: 10.1017/S0956796819000121.Google ScholarGoogle Scholar
  15. Ben R. Gaster, and Mark P. Jones. 1996. A Polymorphic Type System for Extensible Records and Variants. NOTTCS-TR-96-3. University of Nottingham.Google ScholarGoogle Scholar
  16. Carl A. Gunter, Didier Rémy, and Jon G. Riecke. 1995. A Generalization of Exceptions and Control in ML-like Languages. In Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, 12-23. FPCA '95. ACM, La Jolla, California, USA. doi: 10.1145/224164.224173.Google ScholarGoogle Scholar
  17. Daniel Hillerström, and Sam Lindley. 2016. Liberating Efects with Rows and Handlers. In Proceedings of the 1st International Workshop on Type-Driven Development, 15-27. TyDe 2016. Nara, Japan. doi: 10.1145/2976022.2976033.Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Daniel Hillerström, and Sam Lindley. 2018. Shallow Efect Handlers. In 16th Asian Symposium on Programming Languages and Systems (APLAS'18), 415-435. Springer.Google ScholarGoogle Scholar
  19. Daniel Hillerström, Sam Lindley, Bob Atkey, and KC Sivaramakrishnan. Sep. 2017. Continuation Passing Style for Efect Handlers. In Proceedings of the Second International Conference on Formal Structures for Computation and Deduction. FSCD'17.Google ScholarGoogle Scholar
  20. Mark P. Jones. Feb. 1992. A Theory of Qualified Types. In 4th. European Symposium on Programming (ESOP'92), 582 : 287-306. Lecture Notes in Computer Science. Springer-Verlag, Rennes, France. doi: 10.1007/3-540-55253-7_17.Google ScholarGoogle ScholarCross RefCross Ref
  21. Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in Action. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, 145-158. ICFP '13. ACM, New York, NY, USA. doi: 10.1145/2500365.2500590.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Ohad Kammar, and Matija Pretnar. Jan. 2017. No Value Restriction Is Needed for Algebraic Efects and Handlers. Journal of Functional Programming 27 ( 1 ). Cambridge University Press. doi: 10.1017/S0956796816000320.Google ScholarGoogle Scholar
  23. Oleg Kiselyov, Amr Sabry, and Cameron Swords. 2013. Extensible Efects: An Alternative to Monad Transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, 59-70. Haskell ' 13. Boston, Massachusetts, USA. doi: 10.1145/2503778.2503791.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Oleg Kiselyov, and Chung-chieh Shan. 2009. Embedded Probabilistic Programming. In Domain-Specific Languages. doi:10.1007/978-3-642-03034-5_17.Google ScholarGoogle Scholar
  25. Oleg Kiselyov, Chung-chieh Shan, and Amr Sabry. 2006. Delimited Dynamic Binding. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming, 26-37. ICFP '06. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/1159803.1159808.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Daan Leijen. 2005. Extensible Records with Scoped Labels. In Proceedings of the 2005 Symposium on Trends in Functional Programming, 297-312.Google ScholarGoogle Scholar
  27. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Efect Types. In MSFP'14, 5th Workshop on Mathematically Structured Functional Programming. doi:10.4204/EPTCS.153.8.Google ScholarGoogle Scholar
  28. Daan Leijen. 2017a. Implementing Algebraic Efects in C: Or Monads for Free in C. Edited by Bor-Yuh Evan Chang. Programming Languages and Systems, LNCS, 10695 ( 1 ). Suzhou, China: 339-363. APLAS' 17.Google ScholarGoogle Scholar
  29. Daan Leijen. 2017b. Structured Asynchrony with Algebraic Efects. In Proceedings of the 2nd ACM SIGPLAN International Workshop on Type-Driven Development, 16-29. TyDe 2017. Oxford, UK. doi: 10.1145/3122975.3122977.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Daan Leijen. Jan. 2017. Type Directed Compilation of Row-Typed Algebraic Efects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL'17), 486-499. Paris, France. doi: 10.1145/3009837.3009872.Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Daan Leijen. 2019. Koka Repository. https://github.com/koka-lang/koka.Google ScholarGoogle Scholar
  32. Sam Lindley, and James Cheney. 2012. Row-Based Efect Types for Database Integration. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, 91-102. TLDI' 12. doi: 10.1145/2103786.2103798.Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Sam Lindley, Connor McBride, and Craig McLaughlin. Jan. 2017. Do Be Do Be Do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL'17), 500-514. Paris, France. doi: 10.1145/3009837.3009897.Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Simon L Peyton Jones, and John Launchbury. 1995. State in Haskell. Lisp and Symbolic Comp. 8 ( 4 ): 293-341. doi: 10.1007/BF01018827.Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Andrew M. Pitts. 1998. Existential Types: Logical Relations and Operational Equivalence. In In Proceedings of the 25th International Colloquium on Automata, Languages and Programming, 309-326. Springer-Verlag.Google ScholarGoogle Scholar
  36. Atze van der Ploeg, and Oleg Kiselyov. 2014. Reflection without Remorse: Revealing a Hidden Sequence to Speed up Monadic Reflection. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, 133-144. Haskell' 14. Göthenburg, Sweden. doi: 10.1145/2633357.2633360.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Gordon D. Plotkin, and John Power. 2003. Algebraic Operations and Generic Efects. Applied Categorical Structures 11 ( 1 ): 69-94. doi: 10.1023/A: 1023064908962.Google ScholarGoogle ScholarCross RefCross Ref
  38. Gordon D. Plotkin, and Matija Pretnar. 2013. Handling Algebraic Efects. In Logical Methods in Computer Science, volume 9. 4. doi: 10.2168/LMCS-9( 4 :23) 2013.Google ScholarGoogle ScholarCross RefCross Ref
  39. Matija Pretnar. Jan. 2010. Logic and Handling of Algebraic Efects. Phdthesis, University of Edinburgh.Google ScholarGoogle Scholar
  40. Matija Pretnar. Dec. 2015. An Introduction to Algebraic Efects and Handlers. Invited Tutorial Paper. Electron. Notes Theor. Comput. Sci. 319 (C). Elsevier Science Publishers: 19-35. doi: 10.1016/j.entcs. 2015. 12.003.Google ScholarGoogle Scholar
  41. Matija Pretnar, Amr Hany Shehata Saleh, Axel Faes, and Tom Schrijvers. 2017. Eficient Compilation of Algebraic Efects and Handlers. CW Reports. Department of Computer Science, KU Leuven; Leuven, Belgium. https://lirias.kuleuven. be/retrieve/472230.Google ScholarGoogle Scholar
  42. Didier Rémy. 1994. Type Inference for Records in Natural Extension of ML. In Theoretical Aspects of Object-Oriented Programming, 67-95. doi:10.1.1.48.5873.Google ScholarGoogle Scholar
  43. Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2020. Compiling Efect Handlers in CapabilityPassing Style. In Proceedings of the International Conference on Functional Programming. ACM, New York, NY, USA.Google ScholarGoogle Scholar
  44. Sebastian Ullrich, and Leonardo de Moura. Sep. 2019. Counting Immutable Beans-Reference Counting Optimized for Purely Functional Programming. In Proceedings of the 31st Symposium on Implementation and Application of Functional Languages (IFL'19). Singapore.Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Andrew Wright. 1995. Simple Imperative Polymorphism. In LISP and Symbolic Computation, 343-356.Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Nicolas Wu, Tom Schrijvers, and Ralf Hinze. 2014. Efect Handlers in Scope. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, 1-12. Haskell ' 14. Göthenburg, Sweden. doi: 10.1145/2633357.2633358.Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Ningning Xie, Jonathan Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. Jul. 2020. Efect Handlers, Evidently. MSR-TR-2020-23. Microsoft Research. Extended version with proofs.Google ScholarGoogle Scholar
  48. Ningning Xie, and Daan Leijen. Aug. 2020. Efect Handlers in Haskell, Evidently. In Proceedings of the 2020 ACM SIGPLAN Symposium on Haskell. Haskell'20. Jersey City, NJ. doi: 10.1145/3406088.3409022.Google ScholarGoogle Scholar
  49. Yizhou Zhang, and Andrew C. Myers. Jan. 2019. Abstraction-Safe Efect Handlers via Tunneling. Proc. ACM Program. Lang. 3 (POPL). ACM. doi:10.1145/3290318.Google ScholarGoogle Scholar

Index Terms

  1. Effect handlers, evidently

        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 4, Issue ICFP
          August 2020
          1070 pages
          EISSN:2475-1421
          DOI:10.1145/3415018
          Issue’s Table of Contents

          Copyright © 2020 Owner/Author

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 3 August 2020
          Published in pacmpl Volume 4, 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!