Add voidM to Control.Monad

Jurriën Stutterheim j.stutterheim at me.com
Mon Jan 16 14:41:07 CET 2012


Hi all,


I would like to propose adding the following function to Control.Monad to complement the `void` function:

voidM :: Monad m => m a -> m ()
voidM m = m >> return ()

This function would be used to prevent warnings like

    Warning: A do-notation statement discarded a result of type Int.
             Suppress this warning by saying "_ <- bar",
             or by using the flag -fno-warn-unused-do-bind

The (rather contrived) code below was used to generate the warning above:

foo :: IO ()
foo = do
  bar
  return ()

bar :: IO Int
bar = return 1


Using `voidM`, we can rewrite `foo` as such:

foo' :: IO ()
foo' = do
  voidM bar
  return ()

after which no warning will be generated by GHC.


Jurriën


More information about the Libraries mailing list