I was just writing a quick bit of code, and I wanted to use the guard function in the IO Monad. However, there is no definition of MonadPlus for IO which means that we canno
There're functions precisely made for this: in Control.Monad, the functions when and its counterpart unless.
Anthony's answer can be rewritten as such:
handleFlags :: [Flag] -> IO ()
handleFlags flags =
when (Help `elem` flags) $ putStrLn "Usage: program_name options..."
specifications:
when :: (Applicative m) => Bool -> m () -> m ()
unless bool = when (not bool)
Link to docs on hackage.haskell.org
If more is needed, here's a link to another package, specifically monad-oriented and with several more utilities: Control.Monad.IfElse