TY - JOUR AU - Ghani, Neil AB - Composing Monads Using Coproducts Christoph Luth ¨ FB 3 ” Mathematik und Informatik ¨ Universitat Bremen Neil Ghani Dept. Mathematics and Computer Science University of Leicester cxl@informatik.uni-bremen.de ng13@mcs.le.ac.uk Abstract Monads are a useful abstraction of computation, as they model diverse computational effects such as stateful computations, exceptions and I/O in a uniform manner. Their potential to provide both a modular semantics and a modular programming style was soon recognised. However, in general, monads proved dif cult to compose and so research focused on special mechanisms for their composition such as distributive monads and monad transformers. We present a new approach to this problem which is general in that nearly all monads compose, mathematically elegant in using the standard categorical tools underpinning monads and computationally expressive in supporting a canonical recursion operator. In a nutshell, we propose that two monads should be composed by taking their coproduct. Although abstractly this is a simple idea, the actual construction of the coproduct of two monads is non-trivial. We outline this construction, show how to implement the coproduct within Haskell and demonstrate its usage with a few examples. We also discuss its relationship with other ways of combining monads, in particular distributive TI - Composing monads using coproducts DO - 10.1145/581478.581492 DA - 2002-10-04 UR - https://www.deepdyve.com/lp/association-for-computing-machinery/composing-monads-using-coproducts-t0nTuVnFMT DP - DeepDyve ER -