summaryrefslogtreecommitdiff
path: root/ControlMaybe.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ControlMaybe.hs')
-rw-r--r--ControlMaybe.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/ControlMaybe.hs b/ControlMaybe.hs
new file mode 100644
index 0000000..69a38f7
--- /dev/null
+++ b/ControlMaybe.hs
@@ -0,0 +1,23 @@
1{-# LANGUAGE ScopedTypeVariables #-}
2module ControlMaybe where
3
4-- import GHC.IO.Exception (IOException(..))
5import Control.Exception as Exception (IOException(..),catch)
6
7withJust (Just x) f = f x
8withJust Nothing f = return ()
9
10whenJust acn f = do
11 x <- acn
12 withJust x f
13
14
15catchIO_ :: IO a -> IO a -> IO a
16catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h)
17
18catchIO :: IO a -> (IOException -> IO a) -> IO a
19catchIO body handler = Exception.catch body handler
20
21handleIO_ = flip catchIO_
22handleIO = flip catchIO
23