[Haskell-cafe] mapM_ -> Monoid.Monad.map
Henning Thielemann
lemming at henning-thielemann.de
Fri Jan 23 15:50:18 EST 2009
I always considered the monad functions with names ending on '_' a
concession to the IO monad. Would you need them for any other monad than
IO? For self-written monads you would certainly use a monoid instead of
monadic action, all returning (), but IO is a monad. (You could however
wrap (newtype Output = Output (IO ())) and define a Monoid instance on
Output.)
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_ and it is also safer since it connects the monadic result
types of the atomic and the sequenced actions. There was a recent
discussion on the topic:
http://neilmitchell.blogspot.com/2008/12/mapm-mapm-and-monadic-statements.html
More information about the Haskell-Cafe
mailing list