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

Henning Thielemann lemming at henning-thielemann.de
Wed Jun 6 00:13:33 CEST 2012


On Tue, 5 Jun 2012, Andres Löh wrote:

>> Btw. the mapM memory leak can be easily and accidentally resurrected by
>> writing
>>
>>  when_ b (mapM f xs)
>>
>> with
>>
>>  f :: a -> m ()
>>  when_ :: Bool -> m a -> m ()
>
> I don't understand the whole mapM analogy (yet). I don't need when_ to
> get into trouble with using mapM.

If I write

   when b (mapM f xs)

with

   f :: a -> m ()
   when :: Bool -> m () -> m ()

then GHC will say something like: Cannot match [()] (result of 'mapM') 
with () (argument of 'when').



More information about the Libraries mailing list