Interleaving data and effects

The study of programming with and reasoning about inductive datatypes such as lists and trees has benefited from the simple categorical principle of initial algebras. In initial algebra semantics, each inductive datatype is represented by an initial f-algebra for an appropriate functor f. The initial algebra principle then supports the straightforward derivation of definitional principles and proof principles for these datatypes. This technique has been expanded to a whole methodology of structured functional programming, often called origami programming.In this article we show how to extend initial algebra semantics from pure inductive datatypes to inductive datatypes interleaved with computational effects. Inductive datatypes interleaved with effects arise naturally in many computational settings. For example, incrementally reading characters from a file generates a list of characters interleaved with input/output actions, and lazily constructed infinite values can be represented by pure data interleaved with the possibility of non-terminating computation. Straightforward application of initial algebra techniques to effectful datatypes leads either to unsound conclusions if we ignore the possibility of effects, or to unnecessarily complicated reasoning because the pure and effectful concerns must be considered simultaneously. We show how pure and effectful concerns can be separated using the abstraction of initial f-and-m-algebras, where the functor f describes the pure part of a datatype and the monad m describes the interleaved effects. Because initial f-and-m-algebras are the analogue for the effectful setting of initial f-algebras, they support the extension of the standard definitional and proof principles to the effectful setting. Initial f-and-m-algebras are originally due to Filinski and Stovring, who studied them in the category Cpo. They were subsequently generalised to arbitrary categories by Atkey, Ghani, Jacobs, and Johann in a FoSSaCS 2012 paper. In this article we aim to introduce the general concept of initial f-and-m-algebras to a general functional programming audience.

[1]  Claus. Juergensen Using monads to fuse recursive programs , 2002 .

[2]  Uday S. Reddy,et al.  Imperative functional programming , 1996, CSUR.

[3]  Neil Ghani,et al.  Short Cut Fusion of Recursive Programs with Computational Effects , 2008 .

[4]  Andrew M. Pitts,et al.  Relational Properties of Domains , 1996, Inf. Comput..

[5]  Johan Jeuring,et al.  Merging Monads and Folds for Functional Programming , 1995, Advanced Functional Programming.

[6]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[7]  Tim Sheard,et al.  Type parametric programming , 1993 .

[8]  Richard S. Bird,et al.  Algebra of programming , 1997, Prentice Hall International series in computer science.

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

[10]  J. Lambek A fixpoint theorem for complete categories , 1968 .

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

[12]  Stefan Milius,et al.  Coproducts of Monads on Set , 2012, 2012 27th Annual IEEE Symposium on Logic in Computer Science.

[13]  Alberto Pardo Combining Datatypes and Effects , 2004, Advanced Functional Programming.

[14]  S. Lane Categories for the Working Mathematician , 1971 .

[15]  Andrzej Filinski,et al.  Inductive reasoning about effectful data types , 2007, ICFP '07.

[16]  Davide Sangiorgi,et al.  Advanced Topics in Bisimulation and Coinduction: List of contributors , 2011 .

[17]  Thorsten Altenkirch,et al.  Beauty in the beast , 2007, Haskell '07.

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

[19]  Michael Barr,et al.  Category theory for computing science , 1995, Prentice Hall International Series in Computer Science.

[20]  Daniel Lehmann,et al.  Algebraic specification of data types: A synthetic approach , 1981, Mathematical systems theory.

[21]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[22]  Nils Anders Danielsson,et al.  Fast and loose reasoning is morally correct , 2006, POPL '06.

[23]  Bart Jacobs,et al.  An introduction to (co)algebra and (co)induction , 2011, Advanced Topics in Bisimulation and Coinduction.

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

[25]  Nick Benton,et al.  Monads and Effects , 2000, APPSEM.

[26]  Maarten M. Fokkinga Monadic Maps and Folds for Arbitrary Datatypes , 1994 .

[27]  Jeremy Gibbons,et al.  Tracing monadic computations and representing effects , 2012, MSFP.

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

[29]  Walid Taha,et al.  How to add laziness to a strict language without even being odd , 1998 .

[30]  Roy L. Crole,et al.  New Foundations for Fixpoint Computations: FIX-Hyperdoctrines and the FIX-Logic , 1992, Inf. Comput..

[31]  B. Jacobs,et al.  A tutorial on (co)algebras and (co)induction , 1997 .

[32]  Janis Voigtländer,et al.  Asymptotic Improvement of Computations over Free Monads , 2008, MPC.

[33]  Philip S. Mulry,et al.  Lifting Theorems for Kleisli Categories , 1993, MFPS.

[34]  Tarmo Uustalu,et al.  Coproducts of Ideal Monads , 2004, RAIRO Theor. Informatics Appl..

[35]  Bart Jacobs,et al.  Fibrational Induction Meets Effects , 2012, FoSSaCS.