From b52d0975be192c19eb353728d4fc8f1d02e542ff Mon Sep 17 00:00:00 2001 From: "gwern0@gmail.com" Date: Fri, 8 Jan 2010 21:44:55 +0000 Subject: [PATCH] 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-(). --- Control/Monad.hs | 4 ++++ 1 file changed, 4 insertions(+) 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 -- 1.7.10.4