Abstract
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 principle of modular reasoning for higher-order abstractions. We demonstrate that abstraction-safe algebraic effect handlers are possible by giving them a new semantics. The key insight is that code should only handle effects it is aware of. In our approach, the type system guarantees all effects are handled, but it is impossible for higher-order, effect-polymorphic code to accidentally handle effects raised by functions passed in; such effects tunnel through the higher-order, calling procedures polymorphic to them. By contrast, the possibility of accidental handling threatens previous designs for algebraic effect handlers. We prove that our design is not only type-safe, but also abstraction-safe. Using a logical-relations model that we prove sound with respect to contextual equivalence, we derive previously unattainable program equivalence results. Our mechanism offers a viable approach for future language designs aiming for effect handlers with strong abstraction guarantees.
Supplemental Material
- Amal Ahmed. Step-indexed syntactic logical relations for recursive and quantified types. In 15 th European Symposium on Programming, 2006. Extended/corrected version available as Harvard University TR-01-06. Google Scholar
Digital Library
- Andrew W. Appel and David McAllester. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. on Programming Languages and Systems, 23(5), September 2001. Google Scholar
Digital Library
- Andrew W. Appel, Paul-André Melliès, Christopher D. Richards, and Jérôme Vouillon. A very modal model of a modern, major, general type system. In 34 th ACM Symp. on Principles of Programming Languages (POPL), 2007. Google Scholar
Digital Library
- Andrej Bauer and Matija Pretnar. An effect system for algebraic effects and handlers. Logical Methods in Computer Science, Volume 10, Issue 4, December 2014.Google Scholar
Cross Ref
- Andrej Bauer and Matija Pretnar. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84(1), 2015.Google Scholar
Cross Ref
- Nick Benton and Uri Zarfaty. Formalizing and verifying semantic type soundness of a simple compiler. In Proceedings of the 9th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pages 1–12, 2007. Google Scholar
Digital Library
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. Handle with care: Relational interpretation of algebraic effects and handlers. Proc. ACM on Programming Languages, 2(POPL), December 2017. Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser and Philipp Schuster. Effekt: Extensible algebraic effects in Scala (short paper). In Proceedings of the 8th ACM SIGPLAN International Symposium on Scala, 2017. Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. Algebraic effects for the masses. Proc. ACM on Programming Languages, 2(OOPSLA), October 2018.Google Scholar
- Oliver Bračevac, Nada Amin, Guido Salvaneschi, Sebastian Erdweg, Patrick Eugster, and Mira Mezini. Versatile event correlation with algebraic effects. Proc. ACM on Programming Languages, 2(ICFP), August 2018. Google Scholar
Digital Library
- Karl Crary, David Walker, and Greg Morrisett. Typed memory management in a calculus of capabilities. In 26 th ACM Symp. on Principles of Programming Languages (POPL), 1999. Google Scholar
Digital Library
- Olivier Danvy and Andrzej Filinski. Abstracting control. In ACM Conf. on LISP and Functional Programming, pages 151–160, 1990. Google Scholar
Digital Library
- Derek Dreyer. Milner award lecture: The type soundness theorem that you really want to prove (and now you can). In 45 th ACM Symp. on Principles of Programming Languages (POPL), 2018.Google Scholar
- Derek Dreyer, Amal Ahmed, and Lars Birkedal. Logical step-indexed logical relations. In 24th Annual IEEE Symposium on Logic In Computer Science (LICS), 2009. Google Scholar
Digital Library
- Derek Dreyer, Georg Neis, and Lars Birkedal. The impact of higher-order state and control effects on local relational reasoning. Journal of Functional Programming, 22(4-5):477–528, 2012. Google Scholar
Digital Library
- R. Kent Dyvbig, Simon Peyton Jones, and Amr Sabry. A monadic framework for delimited continuations. Journal of Functional Programming, 17(6):687–730, November 2007. ISSN 0956-7968. Google Scholar
Digital Library
- Matthias Felleisen. The calculi of λ-v-CS conversion: A syntactic theory of control and state in imperative higher-order programming languages. PhD thesis, Indiana University, Indianapolis, IN, USA, 1987. Google Scholar
Digital Library
- Mattias Felleisen. The theory and practice of first-class prompts. In 15 th ACM Symp. on Principles of Programming Languages (POPL), pages 180–190, 1988. Google Scholar
Digital Library
- Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley, Reading, MA, 1994. ISBN 0-201-63361-2. Google Scholar
Digital Library
- Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. Region-based memory management in Cyclone. In ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 282–293. ACM Press, 2002. Google Scholar
Digital Library
- Carl A. Gunter, Didier Rémy, and Jon G. Riecke. A generalization of exceptions and control in ml-like languages. In 7 th Conf. on Functional Programming Languages and Computer Architecture (FPCA), 1995. Google Scholar
Digital Library
- Daniel Hillerström and Sam Lindley. Liberating effects with rows and handlers. In Proceedings of the 1st International Workshop on Type-Driven Development, 2016. Google Scholar
Digital Library
- Patricia Johann, Alex Simpson, and Janis Voigtländer. A generic operational metatheory for algebraic effects. In 25th Annual IEEE Symposium on Logic In Computer Science (LICS), 2010. Google Scholar
Digital Library
- Ohad Kammar, Sam Lindley, and Nicolas Oury. Handlers in action. In 18 th ACM SIGPLAN Int’l Conf. on Functional Programming, 2013. Google Scholar
Digital Library
- Donald Ervin Knuth. The TEXbook. Addison-Wesley Reading, 1984.Google Scholar
- Daan Leijen. Koka: Programming with row polymorphic effect types. In 5th Workshop on Mathematically Structured Functional Programming. EPTCS, 2014.Google Scholar
Cross Ref
- Daan Leijen. Type directed compilation of row-typed algebraic effects. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google Scholar
Digital Library
- Jeffrey R. Lewis, John Launchbury, Erik Meijer, and Mark B. Shields. Implicit parameters: Dynamic scoping with static types. In 27 th ACM Symp. on Principles of Programming Languages (POPL), 2000. Google Scholar
Digital Library
- Sam Lindley, Conor McBride, and Craig McLaughlin. Do be do be do. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google Scholar
Digital Library
- Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.Google Scholar
- Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, Cambridge, MA, 1990. ISBN 978-0262631327. Google Scholar
Digital Library
- J. H. Morris, Jr. Lambda-Calculus Models of Programming Languages. PhD thesis, Massachusetts Institute of Technology, 1968.Google Scholar
- Martin Odersky, Olivier Blanvillain, Fengyun Liu, Aggelos Biboudis, Heather Miller, and Sandro Stucki. Simplicitly: Foundations and applications of implicit function types. Proc. ACM on Programming Languages, 2(POPL), December 2017. Google Scholar
Digital Library
- Bruno C.d.S. Oliveira, Adriaan Moors, and Martin Odersky. Type classes as objects and implicits. In 25 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2010. Google Scholar
Digital Library
- Leo Osvald, Grégory Essertel, Xilun Wu, Lilliam I. González Alayón, and Tiark Rompf. Gentrification gone too far? Affordable 2nd-class values for fun and (co-)effect. In 2016 ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2016. Google Scholar
Digital Library
- Andrew M Pitts and Ian Stark. Operational reasoning for functions with local state. Higher order operational techniques in semantics, pages 227–273, 1998. Google Scholar
Digital Library
- Gordon Plotkin and John Power. Algebraic operations and generic effects. Applied Categorical Structures, 11(1):69–94, Feb 2003.Google Scholar
Cross Ref
- Gordon Plotkin and Matija Pretnar. Handling algebraic effects. Logical Methods in Computer Science, Volume 9, Issue 4, December 2013.Google Scholar
Cross Ref
- Piotr Polesiuk. IxFree: Step-indexed logical relations in Coq. In 3 rd International Workshop on Coq for Programming Languages (CoqPL), 2017.Google Scholar
- John C. Reynolds. Types, abstraction and parametric polymorphism. In IFIP Congress, pages 513–523, 1983.Google Scholar
- Lukas Rytz, Martin Odersky, and Philipp Haller. Lightweight polymorphic effects. In 26 th European Conf. on Object-Oriented Programming, 2012. Google Scholar
Digital Library
- Guy L. Steele, Jr. Common LISP: the Language. Digital Press, second edition, 1990. ISBN 1-55558-041-6. Google Scholar
Digital Library
- Mads Tofte and Jean-Pierre Talpin. Region-based memory management. Information and Computation, 132(2):109–176, 1997. Google Scholar
Digital Library
- Philip Wadler. Theorems for free! In 4 th Conf. on Functional Programming Languages and Computer Architecture (FPCA), pages 347–359, September 1989. Google Scholar
Digital Library
- Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1): 38–94, 1994. ISSN 0890-5401. Google Scholar
Digital Library
- Yizhou Zhang and Andrew C. Myers. Abstraction-safe effect handlers via tunneling: technical report. Technical Report 1813– 60202, Cornell University Computing and Information Science, November 2018. URL http://hdl.handle.net/1813/60202 .Google Scholar
- Yizhou Zhang, Guido Salvaneschi, Quinn Beightol, Barbara Liskov, and Andrew C. Myers. Accepting blame for safe tunneled exceptions. In 37 th ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 281–295, June 2016. URL http://www.cs.cornell.edu/andru/papers/exceptions . Google Scholar
Digital Library
Index Terms
Abstraction-safe effect handlers via tunneling
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 ...
Handling bidirectional control flow
Pressed by the difficulty of writing asynchronous, event-driven code, mainstream languages have recently been building in support for a variety of advanced control-flow features. Meanwhile, experimental language designs have suggested effect handlers as ...






Comments