Monad((,)w)实例是否在任何地方都是标准的? [英] Is the `Monad ((,) w)` instance anywhere standard?
问题描述
我一直使用 Writer
的拼写,但我总是要实例化自己:
I use the pair spelling of Writer
all the time, but I always have to instantiate myself:
instance (Monoid w) => Monad ((,) w) where
return x = (mempty, x)
~(w,x) >>= f = let (w', y) = f x in (w `mappend` w', y)
这是否可以在标准库中的任何地方使用?
Does this live anywhere in the standard libraries?
推荐答案
由于camccann在评论中提到, Control.Monad.Instances
仅定义了 Functor
instance。
As camccann mentioned in the comment, Control.Monad.Instances
defines only the Functor
instance.
Control.Monad.Applicative
code> Applicative instance。
Control.Monad.Applicative
defines the Applicative
instance.
变形金刚
包,因此也版本2及以上的
mtl
包,定义一个包装函数 writer ::(a,w) - > Writer wa
。
The transformers
package, and thus also version 2 and above of the
mtl
package, define a wrapper function writer :: (a, w) -> Writer w a
.
但我没有在任何地方找到 Monad
实例。
But I have not found the Monad
instance anywhere.
这篇关于Monad((,)w)实例是否在任何地方都是标准的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!