[Haskell] Types of when and unless in Control.Monad

Henning Thielemann lemming at henning-thielemann.de
Tue Jun 5 21:40:30 CEST 2012

On Tue, 5 Jun 2012, Andreas Abel wrote:

> The reason to have a mapM_ additionally to mapM is that in some cases, e.g. 
> as last statement of a do block of type m (), mapM does not type check.

The functions mapM and mapM_ are really distinct. That's why they are 
generalized in different modules:
   mapM_ is generalized in Foldable
   mapM is generalized in Traversable

Using mapM instead of mapM_ can lead to a memory leak and I think the 
confusion between mapM and mapM_ was the initial reason to add the 
unused-binding warning to GHC. And it actually helped me spotting a lot of 
calls to mapM that have to be calls to mapM_.

More information about the Libraries mailing list