[Haskell-cafe] IO () and IO [()]

Henning Thielemann lemming at henning-thielemann.de
Tue Mar 11 07:43:00 EDT 2008


On Mon, 10 Mar 2008, Neil Mitchell wrote:

>>  I would like to know if in fact there's any difference in practice
>>  between (), [()], i.e. if in practice the difference matters.
>
> Usually, not so much. A lot of Monad functions have _ variants, i.e.
> mapM and mapM_. If you don't need the result, use the mapM_ version,
> as it will run faster and not space/stack leak in some circumstances.

In my opinion, mapM_ and sequence_ are in the wrong class, because they do 
not need much of Monads, or even Functors. They could well live, say, in 
Data.Monoid class. However, it's hard to integrate that in a hierarchy of 
type classes.


instance Monoid a => Monoid (M a) where
    mempty = return mempty
    mappend = liftM2 mappend

where M is a monad type.


More information about the Haskell-Cafe mailing list