
On Wed, Jan 13, 2010 at 10:48 AM, Gwern Branwen
On Wed, Jan 13, 2010 at 10:26 AM, Tyson Whitehead
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.ht...
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