ABSTRACT
Algebraic effect handlers offer an alternative to monads to incorporate effects in Haskell. In recent work Xie _et al._ show how to give semantics to effect handlers in terms of plain polymorphic lambda calculus through _evidence translation_. Besides giving precise semantics, this translation also allows for potentially more efficient implementations. Here we present the first implementation of this technique as a library for effect handlers in Haskell. We show how the design naturally leads to a concise effect interface and how evidence translation enables evaluating _tail resumptive_ operations _in-place_. We give detailed benchmark results where our library performs well with respect to other approaches.
Supplemental Material
- 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 Scholar
- Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. Jan. 2020. Doo Bee Doo Bee Doo. In the Journal of Functional Programming, January. To appear in the special issue on algebraic efects and handlers.Google Scholar
- 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 Scholar
- Richard Eisenberg. Dec. 2012. Decidable Propositional Equality in Haskell. https://typesandkinds.wordpress.com/ 2012 /12/01/decidablepropositional-equality-in-haskell.Google Scholar
- Richard Eisenberg, and Stephanie Weirich. 2012. Dependently Typed Programming with Singletons. In Proceedings of the 2012 Haskell Symposium, 117-130. Haskell ' 12. Copenhagen, Denmark. doi: 10.1145/2364506.2364522.Google ScholarDigital Library
- 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 Scholar
- 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 ScholarDigital Library
- 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 Scholar
- Alexis King. May 2020. Ef: Screaming Fast Extensible Efects for Less. https://github.com/hasura/eff.Google Scholar
- Oleg Kiselyov, and Hiromi Ishii. 2015. Freer Monads, More Extensible Efects. In Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, 94-105. Haskell' 15. Vancouver, BC, Canada. doi: 10.1145/2804302.2804319.Google ScholarDigital Library
- Oleg Kiselyov, Ralf Lämmel, and Keean Schupke. 2004. Strongly Typed Heterogeneous Collections. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, 96-107. Haskell ' 04. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/1017472.1017488.Google ScholarDigital Library
- 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 ScholarDigital Library
- Oleg Kiselyov, and KC Sivaramakrishnan. Dec. 2017. Ef Directly in OCaml. In ML Workshop 2016. http://kcsrk.info/papers/caml-eff17.pdf. Extended version.Google Scholar
- Daan Leijen. 2005. Extensible Records with Scoped Labels. In Proceedings of the 2005 Symposium on Trends in Functional Programming, 297-312.Google Scholar
- Daan Leijen. Sep. 2008. HMF: Simple Type Inference for First-Class Polymorphism. In Proceedings of the 13th ACM Symposium of the International Conference on Functional Programming. ICFP'08. Victoria, Canada. doi: 10.1145/1411204.1411245.Google ScholarDigital Library
- 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 Scholar
- 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 ScholarDigital Library
- Daan Leijen. 2018. First Class Dynamic Efect Handlers: Or, Polymorphic Heaps with Dynamic Efect Handlers. In Proceedings of the 3rd ACM SIGPLAN International Workshop on Type-Driven Development, 51-64. TyDe 2018. St. Louis, MO, USA. doi: 10.1145/3240719.3241789.Google ScholarDigital Library
- Daan Leijen, and Erik Meijer. 2000. Domain Specific Embedded Compilers. In Proceedings of the 2nd Conference on Domain-Specific Languages, 109-122. DSL ' 99. Austin, Texas, USA. doi: 10.1145/331960.331977.Google ScholarDigital Library
- Sheng Liang, Paul Hudak, and Mark Jones. 1995. Monad Transformers and Modular Interpreters. In Proceedings of the 22nd ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, 333-343. POPL '95. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/199448.199528.Google ScholarDigital Library
- Simon Peyton Jones, and John Launchbury. 1995. State in Haskell. Lisp and Symbolic Comp. 8 ( 4 ): 293-341. doi: 10.1007/BF01018827.Google ScholarDigital Library
- Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. Jan. 2007. Practical Type Inference for Arbitrary-Rank Types. J. Funct. Program. 17 ( 1 ). Cambridge University Press, USA: 1-82. doi: 10.1017/S0956796806006034.Google Scholar
- 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 ScholarCross Ref
- Gordon D. Plotkin, and Matija Pretnar. 2013. Handling Algebraic Efects. In Logical Methods in Computer Science, volume 9. 4. doi: 10.2168/ LMCS9 (4:23) 2013.Google ScholarCross Ref
- Tom Schrijvers, Simon Peyton Jones, Manuel Chakravarty, and Martin Sulzmann. 2008. Type Checking with Open Type Functions. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, 51-62. ICFP '08. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/1411204.1411215.Google ScholarDigital Library
- Tom Schrijvers, Maciej Piróg, Nicolas Wu, and Mauro Jaskeliof. 2019. Monad Transformers and Modular Algebraic Efects: What Binds Them Together. In Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell, 98-113. Haskell 2019. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/3331545.3342595.Google ScholarDigital Library
- Wouter Swierstra. Jul. 2008. Data Types à La Carte. Journal of Functional Programming 18 ( 4 ): 423-436. doi: 10.1017/S0956796808006758.Google ScholarDigital Library
- Nicolas Wu, and Tom Schrijvers. 2015a. Fusion for Free: Eficient Algebraic Efect Handlers. In Proceedings of the International Conference on Mathematics of Program Construction. MPC'15. doi:10.1.1.723.5577.Google ScholarCross Ref
- Nicolas Wu, and Tom Schrijvers. 2015b. Fusion for Free: Eficient Algebraic Efect Handlers. In Proceedings of the 12th International Conference on Mathematics of Program Construction, 9129 : 302. Springer, Königswinter, Germany.Google Scholar
- 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 ScholarDigital Library
- Li-yao Xia. Jun. 2018. Heterogeneous Lists with Dependent Types in Haskell. https://blog.poisson.chat/posts/2018-06-06-hlistsdependent-haskell.html.Google Scholar
- Ningning Xie, Jonathan Brachthäuser, Phillip Schuster, Daniel Hillerström, and Daan Leijen. Aug. 2020. Efect Handlers, Evidently. In 25th ACM SIGPLAN International Conference on Functional Programming (ICFP' 2020 ). Jersey City, NJ. doi: 10.1145/3408981.Google Scholar
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors. In Proceedings of the 30th ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, 224-235. POPL '03. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/604131.604150.Google ScholarDigital Library
- Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, 53-66. TLDI '12. Association for Computing Machinery, New York, NY, USA. doi: 10.1145/2103786.2103795.Google ScholarDigital Library
Index Terms
- Effect handlers in Haskell, evidently
Recommendations
Effect handlers, evidently
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 ...
Effects as capabilities: effect handlers and lightweight effect polymorphism
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 ...
Generalized evidence passing for effect handlers: efficient compilation of effect handlers to C
This paper studies compilation techniques for algebraic effect handlers. In particular, we present a sequence of refinements of algebraic effects, going via multi-prompt delimited control, _generalized evidence passing_, yield bubbling, and finally a ...
Comments