From: gwern0@gmail.com Date: Fri, 8 Jan 2010 21:44:55 +0000 (+0000) Subject: Control.Monad: +void :: f a -> f () X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=b52d0975be192c19eb353728d4fc8f1d02e542ff;p=ghc-base.git 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-(). --- diff --git a/Control/Monad.hs b/Control/Monad.hs index a1d7d26..407bfc4 100644 --- a/Control/Monad.hs +++ b/Control/Monad.hs @@ -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