skip to main content

Effects as capabilities: effect handlers and lightweight effect polymorphism

Published:13 November 2020Publication History
Skip Abstract Section

Abstract

Effect handlers have recently gained popularity amongst programming language researchers. Existing type- and effect systems for effect handlers are often complicated and potentially hinder a wide-spread adoption.

We present the language Effekt with the goal to close the gap between research languages with effect handlers and languages for working programmers. The design of Effekt revolves around a different view of effects and effect types. Traditionally, effect types express which side effects a computation might have. In Effekt, effect types express which capabilities a computation requires from its context. While this new point in the design space of effect systems impedes reasoning about purity, we demonstrate that it simplifies the treatment of effect polymorphism and the related issues of effect parametricity and effect encapsulation. To guarantee effect safety, we separate functions from values and treat all functions as second-class. We define the semantics of Effekt as a translation to System Xi, a calculus in explicit capability-passing style.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

Jonathan Brachthäuser presents the OOPSLA 20 paper "Effects as Capabilities: Effect Handlers and Lightweight Effect Polymorphism".

References

  1. Henk P. Barendregt. 1992. Lambda Calculi with Types. In Handbook of Logic in Computer Science (vol. 2 ): Background: Computational Structures. Oxford University Press, New York, NY, USA, 117-309.Google ScholarGoogle Scholar
  2. Andrej Bauer and Matija Pretnar. 2013. An efect system for algebraic efects and handlers. In International Conference on Algebra and Coalgebra in Computer Science. Springer, Berlin, Heidelberg, 1-16.Google ScholarGoogle ScholarCross RefCross Ref
  3. Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic efects and handlers. Journal of Logical and Algebraic Methods in Programming 84, 1 ( 2015 ), 108-123.Google ScholarGoogle ScholarCross RefCross Ref
  4. Nick Benton, Chung-Kil Hur, Andrew J Kennedy, and Conor McBride. 2012. Strongly typed term representations in Coq. Journal of automated reasoning 49, 2 ( 2012 ), 141-159.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2017. Handle with Care: Relational Interpretation of Algebraic Efects and Handlers. Proc. ACM Program. Lang. 2, POPL, Article 8 ( Dec. 2017 ), 30 pages.Google ScholarGoogle Scholar
  6. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting Algebraic Efects. Proc. ACM Program. Lang. 3, POPL, Article 6 ( Jan. 2019 ), 28 pages.Google ScholarGoogle Scholar
  7. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2020. Binders by Day, Labels by Night: Efect Instances via Lexically Scoped Handlers. In Proceedings of the Symposium on Principles of Programming Languages (to appear). ACM, New York, NY, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul Szerlip, Paul Horsfall, and Noah D. Goodman. 2019. Pyro: Deep Universal Probabilistic Programming. J. Mach. Learn. Res. 20, 1 (Jan. 2019 ), 973-978.Google ScholarGoogle Scholar
  9. Jonathan Immanuel Brachthäuser and Philipp Schuster. 2017. Efekt: Extensible Algebraic Efects in Scala (Short Paper). In Proceedings of the International Symposium on Scala (Vancouver, BC, Canada). ACM, New York, NY, USA. https: //doi.org/10.1145/3136000.3136007 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Efect Handlers for the Masses. Proc. ACM Program. Lang. 2, OOPSLA, Article 111 (Oct. 2018 ), 27 pages. https://doi.org/10.1145/3276481 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020a. Efekt: Capability-Passing Style for Typeand Efect-safe, Extensible Efect Handlers in Scala. Journal of Functional Programming ( 2020 ). https://doi.org/10.1017/ S0956796820000027 Google ScholarGoogle ScholarCross RefCross Ref
  12. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020b. Efekt: Lightweight Efect Polymorphism for Handlers. Extended Technical Report. University of Tübingen, Germany. http://ps.informatik.uni-tuebingen.de/ publications/brachthaeuser20efekt.pdf.Google ScholarGoogle Scholar
  13. Jonathan Immanuel Brachthäuser and Daan Leijen. 2019. Programming with Implicit Values, Functions, and Control. Technical Report MSR-TR-2019-7. Microsoft Research.Google ScholarGoogle Scholar
  14. Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23, 5 ( 2013 ), 552-593.Google ScholarGoogle ScholarCross RefCross Ref
  15. Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo Bee Doo Bee Doo. Journal of Functional Programming 30 ( 2020 ), e9. https://doi.org/10.1017/S0956796820000039 Google ScholarGoogle ScholarCross RefCross Ref
  16. Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts. DIKU Rapport 89 /12, DIKU, University of Copenhagen ( 1989 ).Google ScholarGoogle Scholar
  17. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2017. Concurrent system programming with efect handlers. In Proceedings of the Symposium on Trends in Functional Programming. Springer LNCS 10788.Google ScholarGoogle Scholar
  18. Stephen Dolan, Leo White, and Anil Madhavapeddy. 2014. Multicore OCaml. In OCaml Workshop.Google ScholarGoogle Scholar
  19. Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. 2015. Efective concurrency through algebraic efects. In OCaml Workshop.Google ScholarGoogle Scholar
  20. 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 Scholar
  21. Richard A. Eisenberg, Joachim Breitner, and Simon Peyton Jones. 2018. Type Variables in Patterns. In Proceedings of the Haskell Symposium (St. Louis, MO, USA) ( Haskell 2018 ). Association for Computing Machinery, New York, NY, USA, 94-105. https://doi.org/10.1145/3242744.3242753 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Matthias Felleisen. 1988. The Theory and Practice of First-class Prompts. In Proceedings of the Symposium on Principles of Programming Languages (San Diego, California, USA). ACM, New York, NY, USA, 180-190.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 Conference on Functional Programming Languages and Computer Architecture (La Jolla, California, USA). ACM, New York, NY, USA, 12-23.Google ScholarGoogle Scholar
  24. Daniel Hillerström and Sam Lindley. 2016. Liberating Efects with Rows and Handlers. In Proceedings of the Workshop on Type-Driven Development (Nara, Japan). ACM, New York, NY, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Daniel Hillerström, Sam Lindley, Bob Atkey, and KC Sivaramakrishnan. 2017. Continuation Passing Style for Efect Handlers. In Formal Structures for Computation and Deduction (LIPIcs, Vol. 84 ). Schloss Dagstuhl-Leibniz-Zentrum für Informatik.Google ScholarGoogle Scholar
  26. Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in Action. In Proceedings of the International Conference on Functional Programming (Boston, Massachusetts, USA). ACM, New York, NY, USA, 145-158.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Oleg Kiselyov, Chung-chieh Shan, and Amr Sabry. 2006. Delimited Dynamic Binding. In Proceedings of the International Conference on Functional Programming (Portland, Oregon, USA). ACM, New York, NY, USA, 26-37.Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Daan Leijen. 2005. Extensible records with scoped labels. In Proceedings of the Symposium on Trends in Functional Programming. 297-312.Google ScholarGoogle Scholar
  29. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Efect Types. In Proceedings of the Workshop on Mathematically Structured Functional Programming.Google ScholarGoogle ScholarCross RefCross Ref
  30. Daan Leijen. 2016. Algebraic Efects for Functional Programming. Technical Report. MSR-TR-2016-29. Microsoft Research technical report.Google ScholarGoogle Scholar
  31. Daan Leijen. 2017a. Structured Asynchrony with Algebraic Efects. In Proceedings of the Workshop on Type-Driven Development (Oxford, UK). ACM, New York, NY, USA, 16-29.Google ScholarGoogle Scholar
  32. Daan Leijen. 2017b. Type directed compilation of row-typed algebraic efects. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA, 486-499.Google ScholarGoogle Scholar
  33. Daan Leijen. 2018a. Algebraic Efect Handlers with Resources and Deep Finalization. Technical Report MSR-TR-2018-10. Microsoft Research. 35 pages.Google ScholarGoogle Scholar
  34. Daan Leijen. 2018b. First Class Dynamic Efect Handlers: Or, Polymorphic Heaps with Dynamic Efect Handlers. In Proceedings of the Workshop on Type-Driven Development (St. Louis, Missouri, USA). ACM, New York, NY, USA, 51-64.Google ScholarGoogle Scholar
  35. Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Information and Computation 185, 2 ( 2003 ), 182-210.Google ScholarGoogle Scholar
  36. Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do Be Do Be Do. In Proceedings of the Symposium on Principles of Programming Languages (Paris, France). ACM, New York, NY, USA, 500-514.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Jirka Maršík and Maxime Amblard. 2016. Introducing a Calculus of Efects and Handlers for Natural Language Semantics. In International Conference on Formal Grammar. Springer LNCS 9804, 257-272.Google ScholarGoogle Scholar
  38. Andrey Mokhov, Neil Mitchell, and Simon Peyton Jones. 2018. Build Systems à La Carte. Proc. ACM Program. Lang. 2, ICFP, Article 79 ( July 2018 ), 29 pages. https://doi.org/10.1145/3236774 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Dave Moore and Maria Ivanova Gorinova. 2018. Efect Handling for Composable Program Transformations in Edward2. In International Conference on Probabilistic Programming (PROBPROG).Google ScholarGoogle Scholar
  40. Dereck C Oppen. 1980. Prettyprinting. Transactions on Programming Languages and Systems 2, 4 ( 1980 ), 465-483.Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Leo Osvald, Grégory Essertel, Xilun Wu, Lilliam I González Alayón, and Tiark Rompf. 2016. Gentrification gone too far? afordable 2nd-class values for fun and (co-) efect. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. ACM, New York, NY, USA, 234-251.Google ScholarGoogle Scholar
  42. Tomas Petricek, Dominic Orchard, and Alan Mycroft. 2014. Coefects: A Calculus of Context-Dependent Computation. In Proceedings of the International Conference on Functional Programming (Gothenburg, Sweden). ACM, New York, NY, USA, 123-135. https://doi.org/10.1145/2628136.2628160 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Du Phan, Neeraj Pradhan, and Martin Jankowiak. 2019. Composable efects for flexible and accelerated probabilistic programming in NumPyro. arXiv preprint arXiv: 1912. 11554 ( 2019 ).Google ScholarGoogle Scholar
  44. Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Efects. Logical Methods in Computer Science 9, 4 ( 2013 ).Google ScholarGoogle Scholar
  45. Matija Pretnar. 2015. An introduction to algebraic efects and handlers. invited tutorial paper. Electronic Notes in Theoretical Computer Science 319 ( 2015 ), 19-35.Google ScholarGoogle Scholar
  46. Lukas Rytz, Martin Odersky, and Philipp Haller. 2012. Lightweight Polymorphic Efects. In Proceedings of the European Conference on Object-Oriented Programming, James Noble (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 258-282.Google ScholarGoogle Scholar
  47. Philipp Schuster and Jonathan Immanuel Brachthäuser. 2018. Typing, Representing, and Abstracting Control. In Proceedings of the Workshop on Type-Driven Development (St. Louis, Missouri, USA). ACM, New York, NY, USA, 14-24. https: //doi.org/10.1145/3240719.3241788 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2020. Compiling Efect Handlers in CapabilityPassing Style. 4, ICFP, Article 93 ( Aug. 2020 ), 28 pages. https://doi.org/10.1145/3408975 Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Dorai Sitaram. 1993. Handling Control. In Proceedings of the Conference on Programming Language Design and Implementation (Albuquerque, New Mexico, USA). ACM, New York, NY, USA, 147-155.Google ScholarGoogle Scholar
  50. S Doaitse Swierstra and Olaf Chitil. 2009. Linear, bounded, functional pretty-printing. Journal of Functional Programming 19, 01 ( 2009 ), 1-16.Google ScholarGoogle Scholar
  51. Fei Wang, Daniel Zheng, James Decker, Xilun Wu, Grégory M. Essertel, and Tiark Rompf. 2019. Demystifying Diferentiable Programming: Shift/Reset the Penultimate Backpropagator. Proc. ACM Program. Lang. 3, ICFP, Article 96 ( July 2019 ), 31 pages.Google ScholarGoogle Scholar
  52. Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1 (Nov. 1994 ), 38-94.Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Nicolas Wu, Tom Schrijvers, and Ralf Hinze. 2014. Efect Handlers in Scope. In Proceedings of the Haskell Symposium (Gothenburg, Sweden) (Haskell '14). ACM, New York, NY, USA, 1-12.Google ScholarGoogle Scholar
  54. Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. 2020. Efect Handlers, Evidently. 4, ICFP, Article 99 ( Aug. 2020 ), 29 pages. https://doi.org/10.1145/3408981 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Jeremy Yallop. 2017. Staged Generic Programming. Proc. ACM Program. Lang. 1, ICFP, Article 29 ( Aug. 2017 ), 29 pages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe Efect Handlers via Tunneling. Proc. ACM Program. Lang. 3, POPL, Article 5 ( Jan. 2019 ), 29 pages.Google ScholarGoogle Scholar
  57. Yizhou Zhang, Guido Salvaneschi, Quinn Beightol, Barbara Liskov, and Andrew C. Myers. 2016. Accepting Blame for Safe Tunneled Exceptions. In Proceedings of the Conference on Programming Language Design and Implementation (Santa Barbara, CA, USA). ACM, New York, NY, USA, 281-295.Google ScholarGoogle Scholar

Index Terms

  1. Effects as capabilities: effect handlers and lightweight effect polymorphism

        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!