Control.Monad.Writer.Strict .... enough?
Ben Moseley
ben_moseley at mac.com
Thu Jan 15 14:48:07 EST 2009
Hi,
In most of the 'mtl' variants on Hackage (with the notable exception
of 'monadLib'), the Control.Monad.Writer.Strict main instance is:
newtype Writer w a = Writer { runWriter :: (a, w) }
instance (Monoid w) => Monad (Writer w) where
return a = Writer (a, mempty)
m >>= k = Writer $ case runWriter m of
(a, w) -> case runWriter (k a) of
(b, w') -> (b, w `mappend` w')
...ie the `mappend` is hidden inside a lazy "(,)" constructor.
...shouldn't the bind really be strict in the written monoid? (eg by
replacing "(a,w)" with "(a,!w)" and using Bang Patterns).
...if so, is it worth submitting patch?
--Ben
More information about the Libraries
mailing list