Proposal: add "writer" Monad instance (,) o (Ticket #1951)
Conal Elliott
conal at conal.net
Sun Dec 2 12:27:06 EST 2007
I'd like to have a (,)-style writer instance alongside the (->)-based reader
instance for Monad in Control.Monad.Instances.
Here's the current reader:
instance Monad ((->) r) where
return = const
f >>= k = \ r -> k (f r) r
and my proposed writer:
instance Monoid o => Monad ((,) o) where
return = pure
(o,a) >>= f = (o `mappend` o', a') where (o',a') = f a
where the return definition relies on the Applicative instance of ((,) o).
Written out explicitly,
return a = (mempty,a)
Control.Monad.Instances will also need two new imports:
import Data.Monoid (Monoid(..))
import Control.Applicative (pure)
Suggested review period: two weeks (ending Dec 16).
Comments?
- Conal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20071202/abee7096/attachment.htm
More information about the Libraries
mailing list