Control.Monad: +void :: f a -> f ()
authorgwern0@gmail.com <unknown>
Fri, 8 Jan 2010 21:44:55 +0000 (21:44 +0000)
committergwern0@gmail.com <unknown>
Fri, 8 Jan 2010 21:44:55 +0000 (21:44 +0000)
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-().

Control/Monad.hs

index a1d7d26..407bfc4 100644 (file)
@@ -190,6 +190,10 @@ f >=> g     = \x -> f x >>= g
 forever     :: (Monad m) => m a -> m b
 forever a   = a >> forever a
 
+-- | @'void' value@ discards or ignores the result of evaluation, such as the return value of an 'IO' action.
+void :: Functor f => f a -> f ()
+void = fmap (const ())
+
 -- -----------------------------------------------------------------------------
 -- Other monad functions