{-# LANGUAGE FlexibleContexts #-}
module Control.Monad.CatchIO.Try
(
tryIO
, eitherIO
) where
import Control.Exception (IOException)
import Control.Monad.CatchIO (MonadCatchIO,tryJust)
import Control.Monad.Trans.Error (strMsg)
import Control.Monad.Error (MonadError,Error,ErrorType,throwError,MonadIO,liftIO)
tryIO :: (Error (ErrorType m),MonadError m,MonadCatchIO m,Functor m) => IO a -> m a
tryIO :: forall (m :: * -> *) a.
(Error (ErrorType m), MonadError m, MonadCatchIO m, Functor m) =>
IO a -> m a
tryIO = forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
(=<<) (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (m :: * -> *) a. MonadError m => ErrorType m -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Error a => String -> a
strMsg forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) forall (m :: * -> *) a. Monad m => a -> m a
return) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(MonadCatchIO m, Functor m) =>
m a -> m (Either IOException a)
eitherIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
eitherIO :: (MonadCatchIO m,Functor m) => m a -> m (Either IOException a)
eitherIO :: forall (m :: * -> *) a.
(MonadCatchIO m, Functor m) =>
m a -> m (Either IOException a)
eitherIO = forall (m :: * -> *) e b a.
(MonadCatchIO m, Functor m, Exception e) =>
(e -> Maybe b) -> m a -> m (Either b a)
tryJust (forall a. a -> Maybe a
Just :: IOException -> Maybe IOException)