Extending monads with pattern matching

T. Petříček, A. Mycroft, Don Syme
{"title":"Extending monads with pattern matching","authors":"T. Petříček, A. Mycroft, Don Syme","doi":"10.1145/2034675.2034677","DOIUrl":null,"url":null,"abstract":"Sequencing of effectful computations can be neatly captured using monads and elegantly written using <b>do</b> notation. In practice such monads often allow additional ways of composing computations, which have to be written explicitly using combinators.\n We identify joinads, an abstract notion of computation that is stronger than monads and captures many such ad-hoc extensions. In particular, joinads are monads with three additional operations: one of type <i>m</i> <i>a</i> -> <i>m</i> <i>b</i> -> <i>m</i> (<i>a</i>, <i>b</i>) captures various forms of parallel composition, one of type <i>m</i> <i>a</i> -> <i>m</i> <i>a</i> -> <i>m</i> <i>a</i> that is inspired by choice and one of type <i>m</i> <i>a</i> -> <i>m</i> (<i>m</i> a) that captures aliasing of computations. Algebraically, the first two operations form a near-semiring with commutative multiplication.\n We introduce <b>docase</b> notation that can be viewed as a monadic version of <b>case</b>. Joinad laws imply various syntactic equivalences of programs written using <b>docase</b> that are analogous to equivalences about case. Examples of joinads that benefit from the notation include speculative parallelism, waiting for a combination of user interface events, but also encoding of validation rules using the intersection of parsers.","PeriodicalId":188691,"journal":{"name":"ACM SIGPLAN Symposium/Workshop on Haskell","volume":"36 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2012-01-12","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"14","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Symposium/Workshop on Haskell","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/2034675.2034677","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 14

Abstract

Sequencing of effectful computations can be neatly captured using monads and elegantly written using do notation. In practice such monads often allow additional ways of composing computations, which have to be written explicitly using combinators. We identify joinads, an abstract notion of computation that is stronger than monads and captures many such ad-hoc extensions. In particular, joinads are monads with three additional operations: one of type m a -> m b -> m (a, b) captures various forms of parallel composition, one of type m a -> m a -> m a that is inspired by choice and one of type m a -> m (m a) that captures aliasing of computations. Algebraically, the first two operations form a near-semiring with commutative multiplication. We introduce docase notation that can be viewed as a monadic version of case. Joinad laws imply various syntactic equivalences of programs written using docase that are analogous to equivalences about case. Examples of joinads that benefit from the notation include speculative parallelism, waiting for a combination of user interface events, but also encoding of validation rules using the intersection of parsers.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
使用模式匹配扩展单子
有效计算的顺序可以使用单子整齐地捕获,并使用do表示法优雅地编写。在实践中,这样的单子通常允许以其他方式组合计算,这些计算必须使用组合子显式地编写。我们确定了连接点,这是一种抽象的计算概念,它比单子更强大,并捕获了许多这样的特别扩展。特别地,连接是带有三个附加操作的单子:一个是类型m a -> m b -> m (a, b),捕获各种形式的并行组合;一个是类型m a -> m a -> m a,受选择的启发;另一个是类型m a -> m (m a),捕获计算的混叠。在代数上,前两个运算与交换乘法形成近半环。我们引入的docase表示法可以看作是case的一元形式。连接定律意味着使用docase编写的程序的各种语法等价,类似于关于case的等价。受益于该符号的连接示例包括推测并行性,等待用户界面事件的组合,以及使用解析器的交集对验证规则进行编码。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Mio: a high-performance multicore io manager for GHC Understanding idiomatic traversals backwards and forwards An EDSL approach to high performance Haskell programming Causality of optimized Haskell: what is burning our cycles? Splittable pseudorandom number generators using cryptographic hashing
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1