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

Andres Löh andres at well-typed.com
Tue Jun 5 21:58:44 CEST 2012

> 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_.

The different space behaviour is a very good reason to make the
distinction for mapM and mapM_. However, it's not a good reason to
choose arbitrarily restrictive types for perfectly generic functions
in other cases IMHO. At least I don't see that there's a performance
reason not to generalize when or unless, as their implementation would
stay the same.

I'd argue that making functions more restrictive than necessary isn't
an indication of safety, it's just confusing :)


Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com

More information about the Libraries mailing list