darcs patch: Control.Monad: +void :: f a -> f ()
Tyson Whitehead
twhitehead at gmail.com
Wed Jan 13 10:26:19 EST 2010
On January 8, 2010 16:53:07 gwern0 at gmail.com wrote:
> Fri Jan 8 16:44:55 EST 2010 gwern0 at 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 ()?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://www.haskell.org/pipermail/libraries/attachments/20100113/9c658597/attachment.bin
More information about the Libraries
mailing list