From fbf425fbef1c1e60fcdddfbd9b25976162725f97 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 24 Apr 2016 18:43:00 -0400 Subject: Refactored build of executable and library. --- lib/ControlMaybe.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/ControlMaybe.hs (limited to 'lib/ControlMaybe.hs') diff --git a/lib/ControlMaybe.hs b/lib/ControlMaybe.hs new file mode 100644 index 0000000..659dab7 --- /dev/null +++ b/lib/ControlMaybe.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE ScopedTypeVariables #-} +module ControlMaybe where + +-- import GHC.IO.Exception (IOException(..)) +import Control.Exception as Exception (IOException(..),catch) + + +withJust :: Monad m => Maybe x -> (x -> m ()) -> m () +withJust (Just x) f = f x +withJust Nothing f = return () + +whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m () +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_ :: IO a -> IO a -> IO a +handleIO_ = flip catchIO_ + + +handleIO :: (IOException -> IO a) -> IO a -> IO a +handleIO = flip catchIO -- cgit v1.2.3