darcs patch: Control.Monad: +void :: f a -> f ()

Gwern Branwen gwern0 at gmail.com
Wed Jan 13 10:48:39 EST 2010

On Wed, Jan 13, 2010 at 10:26 AM, Tyson Whitehead <twhitehead at gmail.com> wrote:
> I was wondering why forM_ cares about the return type, but then, when I
> checked the type signature, it seems to me like it doesn't
>  forM_ :: Monad m => [a] -> (a -> m b) -> m ()
> Perhaps forkIO and friends should be like this as well.  Replace them with
> something like the following
>  forkIO . (>> return ()) :: IO a -> IO ThreadId
> (presumably this would be optimized away?)
> Cheers!  -Tyson
> PS:  Note that I'm not saying there should be a void function, just wondering
> why all these functions that don't care about return type force it to be ()?

I think the idea is that the type forces the caller to explicitly deal
with the return value, to avoid issues such as space leaks. Neil
Mitchell has made a similar argument for >> forcing an explicit
ignoring: http://neilmitchell.blogspot.com/2008/12/mapm-mapm-and-monadic-statements.html


More information about the Libraries mailing list