[Haskell-cafe] mapM_ -> Monoid.Monad.map

Joachim Breitner mail at joachim-breitner.de
Fri Jan 23 16:30:24 EST 2009


Am Freitag, den 23.01.2009, 21:50 +0100 schrieb Henning Thielemann:
>   However our recent Monoid discussion made me think about mapM_, 
> sequence_, and friends. I think they could be useful for many monads if 
> they would have the type:
>   mapM_ :: (Monoid b) => (a -> m b) -> [a] -> m b
>    I expect that the Monoid instance of () would yield the same efficiency 
> as todays mapM_

will it? This is based on a naive, not well-founded understanding of
haskell evaluation, but looking at
> instance Monoid () where
>	mempty        = ()
>	_ `mappend` _ = ()
>	mconcat _     = ()
I’d assume that evaluating
> mapM_ (putStrLn) lotsOfLargeStrings
with your proposed mapM_ will leave a thunk equivalent to
> () `mappend` () `mappend` () `mappend`...
in memory until the mapM_ has completely finished, where each () is
actually an unevalutated thunk that still has a reference to one of the
elements in the lotsOfLargeStrings list.


Joachim "nomeata" Breitner
  mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090123/1369277e/attachment.bin

More information about the Haskell-Cafe mailing list