{-# LANGUAGE ScopedTypeVariables #-} module ControlMaybe where -- import GHC.IO.Exception (IOException(..)) import Control.Monad import Control.Exception as Exception (IOException(..),catch) import System.IO.Error -- forM_ with less polymorphism. withJust :: Monad m => Maybe x -> (x -> m ()) -> m () withJust m f = forM_ m f {-# INLINE withJust #-} whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m () whenJust acn f = acn >>= mapM_ f {-# INLINE whenJust #-} catchIO_ :: IO a -> IO a -> IO a catchIO_ body catcher = catchIOError body (\_ -> catcher) {-# INLINE catchIO_ #-} handleIO_ :: IO a -> IO a -> IO a handleIO_ catcher body = catchIOError body (\_ -> catcher) {-# INLINE handleIO_ #-} handleIO :: (IOError -> IO a) -> IO a -> IO a handleIO catcher body = catchIOError body catcher {-# INLINE handleIO #-}