Monad transformers and modular algebraic effects: what binds them together

For over two decades, monad transformers have been the main modular approach for expressing purely functional side-effects in Haskell. Yet, in recent years algebraic effects have emerged as an alternative whose popularity is growing. While the two approaches have been well-studied, there is still confusion about their relative merits and expressiveness, especially when it comes to their comparative modularity. This paper clarifies the connection between the two approaches—some of which is folklore—and spells out consequences that we believe should be better known. We characterise a class of algebraic effects that is modular, and show how these correspond to a specific class of monad transformers. In particular, we show that our modular algebraic effects gives rise to monad transformers. Moreover, every monad transformer for algebraic operations gives rise to a modular effect handler.

[1]  Tom Schrijvers,et al.  Fusion for Free - Efficient Algebraic Effect Handlers , 2015, MPC.

[2]  Hayo Thielecke,et al.  Categorical Structure of Continuation Passing Style , 1997 .

[3]  Mauro Jaskelioff Monatron: An Extensible Monad Transformer Library , 2008, IFL.

[4]  Andrzej Filinski,et al.  Representing layered monads , 1999, POPL '99.

[5]  Paul Blain Levy,et al.  Call-by-Push-Value: A Subsuming Paradigm , 1999, TLCA.

[6]  Philip Wadler,et al.  Comprehending monads , 1990, Mathematical Structures in Computer Science.

[7]  Oleg Kiselyov,et al.  Eff Directly in OCaml , 2016, ML/OCAML.

[8]  Pietro Cenciarelli,et al.  A Syntactic Approach to Modularity in Denotational Semantics , 1993 .

[9]  Graham Hutton,et al.  A tutorial on the universality and expressiveness of fold , 1999, Journal of Functional Programming.

[10]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[11]  Gordon D. Plotkin,et al.  Combining effects: Sum and tensor , 2006, Theor. Comput. Sci..

[12]  Andrej Bauer,et al.  An Effect System for Algebraic Effects and Handlers , 2014, Log. Methods Comput. Sci..

[13]  Oleg Kiselyov,et al.  Freer monads, more extensible effects , 2015, Haskell.

[14]  Bruno C. d. S. Oliveira,et al.  Monads, zippers and views: virtualizing the monad stack , 2011, ICFP '11.

[15]  Tom Schrijvers,et al.  Effect handlers in scope , 2014, Haskell 2014.

[16]  J. Michael Spivey,et al.  A Functional Theory of Exceptions , 1990, Sci. Comput. Program..

[17]  Russell O'Connor,et al.  A representation theorem for second-order functionals , 2015, J. Funct. Program..

[18]  Gordon D. Plotkin,et al.  Handlers of Algebraic Effects , 2009, ESOP.

[19]  Mauro Jaskelioff,et al.  Modular Monad Transformers , 2009, ESOP.

[20]  Ohad Kammar,et al.  Handlers in action , 2013, ICFP.

[21]  Conor McBride,et al.  Do be do be do , 2017, POPL.

[22]  Daan Leijen,et al.  Type directed compilation of row-typed algebraic effects , 2017, POPL.

[23]  Sam Lindley,et al.  Compiling Links Effect Handlers to the OCaml Backend , 2016 .

[24]  Amr Sabry,et al.  Extensible effects: an alternative to monad transformers , 2013, Haskell '13.

[25]  Oleg Kiselyov,et al.  Reflection without remorse: revealing a hidden sequence to speed up monadic reflection , 2014, Haskell '14.

[26]  Sam Staton,et al.  Substitution, jumps, and algebraic effects , 2014, CSL-LICS.

[27]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[28]  Edwin Brady,et al.  Programming and reasoning with algebraic effects and dependent types , 2013, ICFP.

[29]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[30]  Gordon D. Plotkin,et al.  Algebraic Operations and Generic Effects , 2003, Appl. Categorical Struct..

[31]  Tom Schrijvers,et al.  From monoids to near-semirings: the essence of MonadPlus and alternative , 2015, PPDP.

[32]  Guy L. Steele,et al.  Building interpreters by composing monads , 1994, POPL '94.

[33]  Gordon D. Plotkin,et al.  Notions of Computation Determine Monads , 2002, FoSSaCS.

[34]  Andrej Bauer,et al.  Programming with algebraic effects and handlers , 2012, J. Log. Algebraic Methods Program..

[35]  Ohad Kammar,et al.  On the expressive power of user-defined effects: effect handlers, monadic reflection, delimited control , 2016, Journal of Functional Programming.

[36]  Ralf Hinze,et al.  Just do it: simple monadic equational reasoning , 2011, ICFP.

[37]  Gordon D. Plotkin,et al.  Handling Algebraic Effects , 2013, Log. Methods Comput. Sci..

[38]  Eugenio Moggi,et al.  Monad transformers as monoid transformers , 2010, Theor. Comput. Sci..

[39]  S. Eilenberg,et al.  Adjoint functors and triples , 1965 .

[40]  Tom Schrijvers,et al.  Syntax and Semantics for Operations with Scopes , 2018, LICS.