Composing monads using coproducts

Composing monads using coproducts
复制标题

使用余积组合 monad

DOI:
--
复制
发表时间:
2002
期刊:
ACM SIGPLAN International Conference on Functional Programming
影响因子:
--
通讯作者:
Neil Ghani
Neil Ghani
中科院分区:
--
文献类型:
--
作者:
Christoph Lüth;Neil Ghani

文献摘要

被引文献

相似文献

单子是计算的有用抽象,因为它们以统一的方式对各种计算效应(例如状态计算,异常和I/O)进行了建模。他们提供模块化语义和模块化编程样式的潜力很快得到了认可。然而,通常,事实证明,单调很难构成,因此研究着重于其组成的特殊机制,例如分布式奇迹和monad变形金刚。我们为这个问题提供了一种新的方法,这几乎所有的单调都构成了数学上优雅的,用于使用在支持规范递归运算符方面,基于单调和计算表达的标准分类工具。简而言之,我们建议应通过取出两个单子来组成两个单子。尽管这是一个简单的想法,但两个单子的共同构造的实际结构是不平凡的。我们概述了这一构造,展示了如何在Haskell中实施相关,并通过一些示例演示其用法。我们还讨论了它与其他结合单子的方法,特别是单调变形金刚的分布定律。
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 difficult 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 laws for monads and monad transformers.