#1951: Add "writer" Monad instance (,) o to Control.Monad.Instances
-------------------------------+--------------------------------------------
Reporter: conal | Owner:
Type: proposal | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.8.1
Severity: normal | Keywords:
Difficulty: Easy (1 hr) | Testcase:
Architecture: Unknown | Os: Unknown
-------------------------------+--------------------------------------------
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)
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1951>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs