为什么没有<<在Haskell标准库中? [英] Why is there no << in the Haskell standard library?

查看:99
本文介绍了为什么没有<<在Haskell标准库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Monad 类定义了一个>> 方法,该方法对两个monadic动作进行排序:

 >> :: Monad m => m a  - > m b  - > mb 

绑定操作符>> = 具有翻转参数等价物, = << ;一元函数组合('鱼')运算符> => <= 。但似乎没有<< (在Hoogling的几分钟后)。这是为什么?



编辑:我知道这不是什么大不了的事。我只是喜欢某些代码行与左指向的操作符的方式。 x < - doSomething =<< doSomethingElse 看起来更好,箭头的方式都是相同的,比 x < - doSomethingElse>> = doSomething

解决方案

据我所知,没有很好的理由。请注意,您的 Monad 也应该是 Applicative 的实例,因此您可以使用< ; * *> 来代替您的排序工具。


The Monad class defines a >> method, which sequences two monadic actions:

>> :: Monad m => m a -> m b -> m b

The binding operator >>= has a flipped-argument equivalent, =<<; as do the monadic function composition ('fish') operators >=> and <=<. There doesn't seem to be a <<, though (after a few minutes of Hoogling). Why is this?

Edit: I know it's not a big deal. I just like the way certain lines of code look with the left-pointing operators. x <- doSomething =<< doSomethingElse just looks nicer, with the arrows all going the same way, than x <- doSomethingElse >>= doSomething.

解决方案

To the best of my knowledge there is no good reason. Note, that your Monad should also be an instance of Applicative, so you can use <* and *> instead as your sequencing tools.

这篇关于为什么没有&lt;&lt;在Haskell标准库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆