A better type signature for `forM_`

Henning Thielemann lemming at henning-thielemann.de
Fri Apr 1 07:06:57 UTC 2016

On Fri, 1 Apr 2016, Erik de Castro Lopo wrote:

> As pointed out to me on IRC (thanks pjdeport), changing the type
> signature of `forM_` to
>    forM_' :: (Monad m, Foldable t) => t a -> (a -> m ()) -> m ()
> would have resulted in an error.

I would prefer that type (and the current behavior could be provided by a 
different function forVoidM_). If people do not want a change, the next 
best solution would be to add forUnitM_ with the type above. Then I could 
add a HLint warning about using current forM_. Or even better: Create a 
new module Data.Foldable.Unit or Control.Monad.Unit and put all result 
ignoring functions like forM_, mapM_, replicateM_ there.

More information about the Libraries mailing list