diff options
author | joe <joe@jerkface.net> | 2013-08-30 17:39:07 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-08-30 17:39:07 -0400 |
commit | 3c531fe8e6c1bdcc934005628d94583328cfe0f8 (patch) | |
tree | 04ca988675f1b6cd808023b2d003420e9e168b7c | |
parent | 6147c5d0c0c6d50270094f42bd7c7c071c475f1e (diff) |
Added ControlMaybe
-rw-r--r-- | ControlMaybe.hs | 23 |
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 #-} | ||
2 | module ControlMaybe where | ||
3 | |||
4 | -- import GHC.IO.Exception (IOException(..)) | ||
5 | import Control.Exception as Exception (IOException(..),catch) | ||
6 | |||
7 | withJust (Just x) f = f x | ||
8 | withJust Nothing f = return () | ||
9 | |||
10 | whenJust acn f = do | ||
11 | x <- acn | ||
12 | withJust x f | ||
13 | |||
14 | |||
15 | catchIO_ :: IO a -> IO a -> IO a | ||
16 | catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h) | ||
17 | |||
18 | catchIO :: IO a -> (IOException -> IO a) -> IO a | ||
19 | catchIO body handler = Exception.catch body handler | ||
20 | |||
21 | handleIO_ = flip catchIO_ | ||
22 | handleIO = flip catchIO | ||
23 | |||