Skip to main content Accessibility help
×
Home

On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control

  • YANNICK FORSTER (a1), OHAD KAMMAR (a2), SAM LINDLEY (a3) and MATIJA PRETNAR (a4)

Abstract

We compare the expressive power of three programming abstractions for user-defined computational effects: Plotkin and Pretnar’s effect handlers, Filinski’s monadic reflection, and delimited control. This comparison allows a precise discussion about the relative expressiveness of each programming abstraction. It also demonstrates the sensitivity of the relative expressiveness of user-defined effects to seemingly orthogonal language features. We present three calculi, one per abstraction, extending Levy’s call-by-push-value. For each calculus, we present syntax, operational semantics, a natural type-and-effect system, and, for effect handlers and monadic reflection, a set-theoretic denotational semantics. We establish their basic metatheoretic properties: safety, termination, and, where applicable, soundness and adequacy. Using Felleisen’s notion of a macro translation, we show that these abstractions can macro express each other, and show which translations preserve typeability. We use the adequate finitary set-theoretic denotational semantics for the monadic calculus to show that effect handlers cannot be macro expressed while preserving typeability either by monadic reflection or by delimited control. Our argument fails with simple changes to the type system such as polymorphism and inductive types. We supplement our development with a mechanised Abella formalisation.

Copyright

References

Hide All
Asai, K. (2009) On typing delimited continuations: three new solutions to the printf problem. Higher-Order Symb. Comput. 22(3), 275291.
Asai, K. & Kameyama, Y. (2007) Polymorphic delimited continuations. In Programming Languages and Systems, Shao, Z. (ed). Berlin, Heidelberg: Springer, pp. 239254.
Atkey, R. (2009) Parameterised notions of computation. J. Funct. Program. 19(3–4), 335376.
Baelde, D., Chaudhuri, K., Gacek, A., Miller, D., Nadathur, G., Tiu, A. & Wang, Y. (2014) Abella: a system for reasoning about relational specifications. J. Form. Reason. 7(2), 189.
Barr, M. & Wells, C. (1985) Toposes, Triples, and Theories. Grundlehren der mathematischen Wissenschaften. Springer-Verlag.
Bauer, A. & Pretnar, M. (2014) An effect system for algebraic effects and handlers. Log. Methods Comput. Sci. 10(4), 29 pages.
Bauer, A. & Pretnar, M. (2015) Programming with algebraic effects and handlers. J. Logical Alg. Methods Program. 84(1), 108123. Special Issue: Domains X, International workshop on Domain Theory and applications, Swansea, er 5–7, 2011.
Brachthauser, J. & Leijen, D. (2019) Programming with Implicit Values, Functions, and Control (or, Implicit Functions: Dynamic Binding with Lexical Scoping). Technical Report MSR-TR-2019-7. Microsoft.
Brady, E. (2013) Programming and reasoning with algebraic effects and dependent types. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming. ICFP’13. New York, NY, USA: ACM, pp. 133–144.
Bračevac, O., Amin, N., Salvaneschi, G., Erdweg, S., Eugster, P. & Mezini, M. (2018) Versatile event correlation with algebraic effects. Proc. ACM Program. Lang. 2(ICFP), 67:1–67:31.
Bulwahn, L., Krauss, A., Haftmann, F., Erkök, L. & Matthews, J. (2008). Imperative functional programming with Isabelle/HOL. In Theorem Proving in Higher Order Logics, Mohamed, O. A., Muñoz, C., & Tahar, S. (eds). Berlin, Heidelberg: Springer, pp. 134149.
Danvy, O. (2006) An Analytical Approach to Programs as Data Objects. DSc dissertation, Department of Computer Science, University of Aarhus.
Danvy, O. & Filinski, A. (1989) A Functional Abstraction of Typed Contexts. Technical Report 89/12. DIKU.
Danvy, O. & Filinski, A. (1990) Abstracting control. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming. LFP’90. New York, NY, USA: ACM, pp. 151–160.
Doczkal, C. (2007) Strong Normalization of CBPV. Technical Report, Saarland University.
Doczkal, C. & Schwinghammer, J. (2009) Formalizing a strong normalization proof for moggi’s computational metalanguage: a case study in Isabelle/HOL-nominal. In Proceedings of the Fourth International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice. LFMTP’09. New York, NY, USA: ACM, pp. 57–63.
Felleisen, M. (1991) On the expressive power of programming languages. Sci. Comput. Program. 17(1), 3575.
Felleisen, M. & Friedman, D. P. (1987) A reduction semantics for imperative higher-order languages. In PARLE Parallel Architectures and Languages Europe, de Bakker, J. W., Nijman, A. J. & Treleaven, P. C. (eds). Berlin, Heidelberg: Springer, pp. 206223.
Felleisen, M., Wand, M., Friedman, D. & Duba, B. (1988) Abstract continuations: a mathematical semantics for handling full jumps. In Proceedings of the 1988 ACM Conference on LISP and Functional Programming. LFP’88. New York, NY, USA: ACM, pp. 52–62.
Filinski, A. (1994) Representing monads. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’94. New York, NY, USA: ACM, pp. 446–457.
Filinski, A. (1996) Controlling Effects. PhD thesis, School of Computer Science, Carnegie Mellon University, Pittsburgh, Pennsylvania.
Filinski, A. (1999) Representing layered monads. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’99. New York, NY, USA: ACM, pp. 175–188.
Filinski, A. (2010) Monads in action. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’10. New York, NY, USA: ACM, pp. 483–494.
Forster, Y. (2016) On the Expressive Power of Effect Handlers and Monadic Reflection. Technical Report, University of Cambridge.
Forster, Y., Kammar, O., Lindley, S. & Pretnar, M. (2017) On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control. Proc. ACM Program. Lang. 1(ICFP), 13:1–13:29.
Forster, Y., Schäfer, S., Spies, S. & Stark, K. (2019) Call-by-push-value in Coq: operational, equational, and denotational theory. In Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs. CPP 2019. New York, NY, USA: ACM, pp. 118–131.
Gacek, A. (2008) The Abella interactive theorem prover (system description). In Automated Reasoning, Armando, A., Baumgartner, P. & Dowek, G. (eds). Berlin, Heidelberg: Springer, pp. 154161.
Gacek, A. (2009) A Framework for Specifying, Prototyping, and Reasoning about Computational Systems. PhD thesis, University of Minnesota.
Hermida, C. (1993) Fibrations, Logical Predicates and Related Topics. PhD thesis, University of Edinburgh.
Hillerström, D. & Lindley, S. (2016) Liberating effects with rows and handlers. In Proceedings of the 1st International Workshop on Type-Driven Development. TyDe 2016. New York, NY, USA: ACM, pp. 15–27.
Hillerström, D., Lindley, S., Atkey, R. & Sivaramakrishnan, K. C. (2017) Continuation Passing style for effect handlers. In 2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017), Miller, D. (ed). Leibniz International Proceedings in Informatics (LIPIcs), vol. 84. Dagstuhl, Germany: Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, pp. 18:1–18:19.
Hutton, G. & Meijer, E. (1998) Monadic parsing in Haskell. J. Funct. Program. 8(4), 437444.
Inostroza, P. & van der Storm, T. (2018) JEff: objects for effect. In Proceedings of the 2018 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software. Onward! 2018. New York, NY, USA: ACM, pp. 111–124.
Kammar, O. (2014) An Algebraic Theory of Type-and-Effect Systems. PhD thesis, University of Edinburgh.
Kammar, O., Lindley, S. & Oury, N. (2013) Handlers in action. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming. ICFP’13. New York, NY, USA: ACM, pp. 145–158.
Kammar, O. & McDermott, D. (2018) Factorisation systems for logical relations and monadic lifting in type-and-effect system semantics. Electron. Notes Theor. Comput. Sci. 341, 239260. Proceedings of the Thirty-Fourth Conference on the Mathematical Foundations of Programming Semantics (MFPS XXXIV).
Kammar, O. & Plotkin, G. D. (2012) Algebraic foundations for effect-dependent optimisations. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’12. New York, NY, USA: ACM, pp. 349–360.
Kammar, O. & Pretnar, M. (2017) No value restriction is needed for algebraic effects and handlers. J. Funct. Program. 27, e7.
Katsumata, S. (2014) Parametric effect monads and semantics of effect systems. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’14. New York, NY, USA: ACM, pp. 633–645.
Kiselyov, O. (2016) Parameterized extensible effects and session types (extended abstract). In Proceedings of the 1st International Workshop on Type-Driven Development. TyDe 2016. New York, NY, USA: ACM, pp. 41–42.
Kiselyov, O., Friedman, D. P. & Sabry, A. A. (2005) How to Remove a Dynamic Prompt: Static and Dynamic Delimited Continuation Operators are Equally Expressible. Technical Report TR611, Indiana University School of Informatics and Computing.
Kiselyov, O., Sabry, A. & Swords, C. (2013) Extensible effects: an alternative to monad transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell. Haskell’13. New York, NY, USA: ACM, pp. 59–70.
Kiselyov, O. & Shan, C.-c. (2007) A substructural type system for delimited continuations. In Typed Lambda Calculi and Applications, Della Rocca, S. R. (ed). Berlin, Heidelberg: Springer, pp. 223239.
Kiselyov, O., Shan, C.-c. & Sabry, A. (2006). Delimited dynamic binding. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming. ICFP’06. New York, NY, USA: ACM, pp. 26–37.
Kiselyov, O. & Sivaramakrishnan, K. C. (2018) Eff directly in OCaml. In Proceedings ML Family Workshop/OCaml Users and Developers workshops, Nara, Japan, September 22–23, 2016, Asai, K. & Shinwell, M. (eds). Electronic Proceedings in Theoretical Computer Science, vol. 285. Open Publishing Association, pp. 23–58.
Kobori, I., Kameyama, Y. & Kiselyov, O. (2016) Answer-type modification without tears: prompt-passing style translation for typed delimited-control operators. In Proceedings of the Workshop on Continuations, London, UK, April 12, 2015, Danvy, O. & de’Liguoro, U. (eds). Electronic Proceedings in Theoretical Computer Science, vol. 212. Open Publishing Association, pp. 36–52.
Laird, J. (2002) Exceptions, continuations and macro-expressiveness. In Programming Languages and Systems, Le Métayer, D. (ed). Berlin, Heidelberg: Springer, pp. 133146.
Laird, J. (2013) Combining and relating control effects and their semantics. In Proceedings First Workshop on Control Operators and their Semantics, Eindhoven, The Netherlands, June 24–25, 2013, de’Liguoro, U. & Saurin, A. (eds). Electronic Proceedings in Theoretical Computer Science, vol. 127. Open Publishing Association, pp. 113–129.
Laird, J. (2017) Combining control effects and their models: game semantics for a hierarchy of static, dynamic and delimited control effects. Ann. Pure Appl. Logic 168(2), 470500. Eighth Games for Logic and Programming Languages Workshop (GaLoP).
Leijen, D. (2017) Type directed compilation of row-typed algebraic effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. POPL 2017. New York, NY, USA: ACM, pp. 486–499.
Levy, P. B. (2003) Call-by-Push-Value: A Functional/Imperative Synthesis. Semantics Structures in Computation, vol. 2. Dordrecht, Netherlands: Springer.
Lindley, S., McBride, C. & McLaughlin, C. (2017) Do be do be do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. POPL 2017. New York, NY, USA: ACM, pp. 500–514.
Lindley, S. & Stark, I. (2005) Reducibility and ⊺⊺-lifting for computation types. In Typed Lambda Calculi and Applications, Urzyczyn, P. (ed). Berlin, Heidelberg: Springer, pp. 262277.
Lucassen, J. M. & Gifford, D. K. (1988) Polymorphic effect systems. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. POPL’88. New York, NY, USA: ACM, pp. 47–57.
Marmolejo, F. & Wood, R. J. (2010) Monads as extension systems—no iteration is necessary. Theory Appl. Categor. 24(4), 84113.
Materzok, M. & Biernacki, D. (2012) A dynamic interpretation of the CPS hierarchy. In Programming Languages and Systems, Jhala, R. & Igarashi, A. (eds). Berlin, Heidelberg: Springer, pp. 296311.
Moggi, E. (1989) Computational lambda-calculus and monads. In Proceedings of the Fourth Annual Symposium on Logic in Computer Science. Piscataway, NJ, USA: IEEE, pp. 14–23.
Paré, R. (1974) Colimits in topoi. Bull. Amer. Math. Soc. 80(3), 556561.
Piróg, M., Polesiuk, P. & Sieczkowski, F. (2019) Typed equivalence of effect handlers and delimited control. In 4th International Conference on Formal Structures for Computation and Deduction (FSCD 2019), Geuvers, H. (ed). Leibniz International Proceedings in Informatics (LIPIcs), vol. 131. Dagstuhl, Germany: Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, pp. 30:1–30:16.
Plotkin, G. & Power, J. (2002) Notions of computation determine monads. In Foundations of Software Science and Computation Structures, Nielsen, M. & Engberg, U. (eds). Berlin, Heidelberg: Springer, pp. 342356.
Plotkin, G. & Power, J. (2003) Algebraic operations and generic effects. Appl. Categor. Struct. 11(1), 6994.
Plotkin, G. & Pretnar, M. (2008) A logic for algebraic effects. In Proceedings of the 2008 23rd Annual IEEE Symposium on Logic in Computer Science. LICS’08. Washington, DC, USA: IEEE Computer Society, pp. 118–129.
Plotkin, G. & Pretnar, M. (2009) Handlers of algebraic effects. In Programming Languages and Systems, Castagna, G. (ed). Berlin, Heidelberg: Springer, pp. 8094.
Pretnar, M. (2014) Inferring algebraic effects. Logical Methods Comput. Sci. 10(3), 43 pages.
Pretnar, M. (2015) An introduction to algebraic effects and handlers. invited tutorial paper. Electron. Notes Theoret. Comput. Sci. 319, 1935. The 31st Conference on the Mathematical Foundations of Programming Semantics (MFPS XXXI).
Reynolds, J. C. (1998) Theories of Programming Languages. Cambridge University.
Saleh, A. H., Karachalias, G., Pretnar, M. & Schrijvers, T. (2018). Explicit effect subtyping. In Programming Languages and Systems, Ahmed, A. (ed). Cham: Springer International Publishing, pp. 327354.
Schrijvers, T., Piróg, M., Wu, N. & Jaskelioff, M. (to appear) Monad transformers and modular algebraic effects: what binds them together. In Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell. Haskell 2019. New York, NY, USA: ACM.
Schrijvers, T., Tack, G., Wuille, P., Samulowitz, H. & Stuckey, P. J. (2013) Search combinators. Constraints 18(2), 269305.
Shan, C.-c. (2007) A static simulation of dynamic delimited control. Higher-Order Symb. Comput. 20(4), 371401.
Sinkovics, Á. & Porkoláb, Z. (2013) Implementing monads for C++ template metaprograms. Sci. Comput. Program. 78(9), 16001621.
Spivey, M. (1990) A functional theory of exceptions. Sci. Comput. Program. 14(1), 2542.
Swierstra, W. (2008) Data types à la carte. J. Funct. Program. 18(4), 423436.
Tait, W. W. (1967) Intensional interpretations of functionals of finite type I. J. Symb. Logic 32(2), 198212.
Wadler, P. (1990) Comprehending monads. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming. LFP’90. New York, NY, USA: ACM, pp. 61–78.
Wadler, P. (1994) Monads and composable continuations. Lisp Symb. Comput. 7(1), 3955.
Wright, A. K. & Felleisen, M. (1994) A syntactic approach to type soundness. Infor. Comput. 115(1), 3894.
Zhang, Y. & Myers, A. C. (2019) Abstraction-safe effect handlers via tunneling. Proc. ACM Program. Lang. 3(POPL), 5:1–5:29.
Ziliani, B., Dreyer, D., Krishnaswami, N. R., Nanevski, A. & Vafeiadis, V. (2015) Mtac: a monad for typed tactic programming in Coq. J. Funct. Program. 25, e12.

On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control

  • YANNICK FORSTER (a1), OHAD KAMMAR (a2), SAM LINDLEY (a3) and MATIJA PRETNAR (a4)

Metrics

Altmetric attention score

Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control

  • YANNICK FORSTER (a1), OHAD KAMMAR (a2), SAM LINDLEY (a3) and MATIJA PRETNAR (a4)
Submit a response

Discussions

No Discussions have been published for this article.

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *