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.
Supplemental Material
- 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 Scholar
- Andrej Bauer, and Matija Pretnar. 2014. An Efect System for Algebraic Efects and Handlers. Logical Methods in Computer Science 10 ( 4 ).Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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
- 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 Scholar
- Jonathan Immanuel Brachthäuser, and Philipp Schuster. Oct. 2017. Efekt: Extensible Algebraic Efects in Scala. In Scala' 17. Vancouver, CA.Google Scholar
- 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 Scholar
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Efekt: Lightweight Efect Polymorphism for Handlers. Technical Report. University of Tübingen, Germany.Google Scholar
- 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 Scholar
- 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 Scholar
- Stephen Dolan, Leo White, KC Sivaramakrishnan, Jeremy Yallop, and Anil Madhavapeddy. Sep. 2015. Efective Concurrency through Algebraic Efects. In OCaml Workshop.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
- 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 Scholar
- 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
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital 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
- 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 Scholar
Digital Library
- Oleg Kiselyov, and Chung-chieh Shan. 2009. Embedded Probabilistic Programming. In Domain-Specific Languages. doi:10.1007/978-3-642-03034-5_17.Google Scholar
- 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 Scholar
Digital Library
- 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. 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. 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Daan Leijen. 2019. Koka Repository. https://github.com/koka-lang/koka.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Simon L Peyton Jones, and John Launchbury. 1995. State in Haskell. Lisp and Symbolic Comp. 8 ( 4 ): 293-341. doi: 10.1007/BF01018827.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Matija Pretnar. Jan. 2010. Logic and Handling of Algebraic Efects. Phdthesis, University of Edinburgh.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Andrew Wright. 1995. Simple Imperative Polymorphism. In LISP and Symbolic Computation, 343-356.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Index Terms
Effect handlers, evidently
Recommendations
Effect handlers in Haskell, evidently
Haskell 2020: Proceedings of the 13th ACM SIGPLAN International Symposium on HaskellAlgebraic 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 ...
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 ...
Abstraction-safe effect handlers via tunneling
Algebraic effect handlers offer a unified approach to expressing control-flow transfer idioms such as exceptions, iteration, and async/await. Unfortunately, previous attempts to make these handlers type-safe have failed to support the fundamental ...






Comments