Implementing collection classes with monads

In object-oriented programming, there are many notions of ‘collection with members in X’. This paper offers an axiomatic theory of collections based on monads in the category of sets and total functions. Heuristically, the axioms defining a collection monad state that each collection has a finite set of members of X, that pure 1-element collections exist and that a collection of collections flattens to a single collection whose members are the union of the members of the constituent collections. The relationship between monads and universal algebra leads to a formal definition of collection implementation in terms of tree-processing. Ideas from elementary category theory underly the classification of collections. For example, collections can be zipped if and only if the monad's endofunctor preserves pullbacks. Or, a collection can be uniquely specified by its shape and list of data if the morphisms of the Kleisli category of the monad are all deterministic, and the converse holds for commutative monads. Again, a collection monad is ordered if the monad's functor preserves equalizers of monomorphisms (so, in particular, if collections can be zipped the monad is ordered). Every implementable monad is ordered. It is shown using the well-ordering principle that a collection monad is ordered if and only if its functor admits an appropriated list-valued natural transformation that lists the members of each collection.

[1]  Philip Wadler,et al.  Comprehending monads , 1990, LISP and Functional Programming.

[2]  Simon Peyton Jones,et al.  The Implementation of Functional Programming Languages (Prentice-hall International Series in Computer Science) , 1987 .

[3]  Andrzej Filinski,et al.  Representing monads , 1994, POPL '94.

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

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

[6]  E. Manes A class of fuzzy theories , 1982 .

[7]  H. Kleisli,et al.  Every standard construction is induced by a pair of adjoint functors , 1965 .

[8]  F. W. Lawvere,et al.  FUNCTORIAL SEMANTICS OF ALGEBRAIC THEORIES. , 1963, Proceedings of the National Academy of Sciences of the United States of America.

[9]  A. Kock Monads on symmetric monoidal closed categories , 1970 .

[10]  Limsoon Wong,et al.  Principles of Programming with Complex Objects and Collection Types , 1995, Theor. Comput. Sci..

[11]  Ernest G. Manes Predicate transformer semantics , 1992, Cambridge tracts in theoretical computer science.

[12]  A. Kock Bilinearity and Cartesian Closed Monads. , 1971 .

[13]  M. Barr,et al.  Toposes, Triples and Theories , 1984 .

[14]  Hung T. Nguyen,et al.  Uncertainty Models for Knowledge-Based Systems; A Unified Approach to the Measurement of Uncertainty , 1985 .

[15]  Eugenio Moggi A Semantics for Evaluation Logic , 1995, Fundam. Informaticae.

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

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

[18]  G. Birkhoff,et al.  On the Structure of Abstract Algebras , 1935 .

[19]  Z. Ésik,et al.  Iteration Theories: The Equational Logic of Iterative Processes , 1993 .

[20]  C. Barry Jay,et al.  A Semantics for Shape , 1995, Sci. Comput. Program..

[21]  W. Taylor Equational logic , 1979 .