
On January 8, 2010 16:53:07 gwern0@gmail.com wrote:
Fri Jan 8 16:44:55 EST 2010 gwern0@gmail.com * Control.Monad: +void :: f a -> f () See http://hackage.haskell.org/trac/ghc/ticket/3292 Turns m a -> m (). Lets one call functions for their side-effects without having to get rid of their return values with '>> return ()'. Very useful in many contexts (parsing, IO etc.); particularly good for 'forkIO' and 'forM_', as they demand return types of 'IO ()' though most interesting IO functions return non-().
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 ()?