From 3c531fe8e6c1bdcc934005628d94583328cfe0f8 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 30 Aug 2013 17:39:07 -0400 Subject: Added ControlMaybe --- ControlMaybe.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ControlMaybe.hs diff --git a/ControlMaybe.hs b/ControlMaybe.hs new file mode 100644 index 0000000..69a38f7 --- /dev/null +++ b/ControlMaybe.hs @@ -0,0 +1,23 @@ +{-# LANGUAGE ScopedTypeVariables #-} +module ControlMaybe where + +-- import GHC.IO.Exception (IOException(..)) +import Control.Exception as Exception (IOException(..),catch) + +withJust (Just x) f = f x +withJust Nothing f = return () + +whenJust acn f = do + x <- acn + withJust x f + + +catchIO_ :: IO a -> IO a -> IO a +catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h) + +catchIO :: IO a -> (IOException -> IO a) -> IO a +catchIO body handler = Exception.catch body handler + +handleIO_ = flip catchIO_ +handleIO = flip catchIO + -- cgit v1.2.3