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

David Menendez dave at zednenem.com
Wed Jan 13 12:07:20 EST 2010


On Wed, Jan 13, 2010 at 10:48 AM, Gwern Branwen <gwern0 at gmail.com> wrote:
> 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

I've never found this argument particularly convincing. I'd much
rather generalize the types of fork and forM_ than introduce more
trivial functions like void.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Libraries mailing list