summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-08-30 17:39:07 -0400
committerjoe <joe@jerkface.net>2013-08-30 17:39:07 -0400
commit3c531fe8e6c1bdcc934005628d94583328cfe0f8 (patch)
tree04ca988675f1b6cd808023b2d003420e9e168b7c
parent6147c5d0c0c6d50270094f42bd7c7c071c475f1e (diff)
Added ControlMaybe
-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