Freer monads, more extensible effects

We present a rational reconstruction of extensible effects, the recently proposed alternative to monad transformers, as the confluence of efforts to make effectful computations compose. Free monads and then extensible effects emerge from the straightforward term representation of an effectful computation, as more and more boilerplate is abstracted away. The generalization process further leads to freer monads, constructed without the Functor constraint. The continuation exposed in freer monads can then be represented as an efficient type-aligned data structure. The end result is the algorithmically efficient extensible effects library, which is not only more comprehensible but also faster than earlier implementations. As an illustration of the new library, we show three surprisingly simple applications: non-determinism with committed choice (LogicT), catching IO exceptions in the presence of other effects, and the semi-automatic management of file handles and other resources through monadic regions. We extensively use and promote the new sort of `laziness', which underlies the left Kan extension: instead of performing an operation, keep its operands and pretend it is done.

[1]  Olivier Danvy,et al.  Abstracting control , 1990, LISP and Functional Programming.

[2]  Matthias Felleisen,et al.  The Denotational Specifications of Complex Languages , 2005 .

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

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

[5]  John Hughes,et al.  The Design of a Pretty-printing Library , 1995, Advanced Functional Programming.

[6]  Lee Naish,et al.  Pruning in Logic Programming , 1995 .

[7]  Ralf Hinze,et al.  Deriving backtracking monad transformers , 2000, ICFP '00.

[8]  Christoph Lüth,et al.  Composing monads using coproducts , 2002, ICFP '02.

[9]  J. Gregory Morrisett,et al.  Monadic regions , 2004, ICFP '04.

[10]  Koen Claessen Parallel Parsing Processes , 2004, J. Funct. Program..

[11]  Emir Pasalic,et al.  Two-level types and parameterized modules , 2004, Journal of Functional Programming.

[12]  Amr Sabry,et al.  Backtracking, interleaving, and terminating monad transformers: (functional pearl) , 2005, ICFP '05.

[13]  Programming monads operationally with Unimo , 2006, ICFP '06.

[14]  Chung-chieh Shan,et al.  Lightweight monadic regions , 2008, Haskell '08.

[15]  Patricia Johann,et al.  Foundations for structured programming with GADTs , 2008, POPL '08.

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

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

[18]  Alexander Katovsky,et al.  Category Theory , 2010, Arch. Formal Proofs.

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

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

[21]  Andy Gill,et al.  The constrained-monad problem , 2013, ICFP.

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

[23]  Jean-Philippe Bernardy,et al.  Names for free: polymorphic views of names and binders , 2013, Haskell '13.

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

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

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

[27]  Patrick Bahr Composing and decomposing data types: a closed type families implementation of data types à la carte , 2014, WGP '14.

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

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