-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A 'Failable' error monad class to unify failure across monads that can fail -- -- This library contains a Failable error monad class to unify -- failure across monads and transformers most commonly used to implement -- pipelines that can fail and does so in a simple nonsense way by -- providing the means of signaling a computation "failure" while -- striving to keep the failure behaviour consistent with the actual -- definition of the monad/transformer. Please refer to the README file -- for a more elaborate description and some examples. @package failable @version 1.0.0.0 -- | This library provides a Failable error monad class to unify -- errors across monads and transformers most commonly used to implement -- pipelines that can fail. module Control.Monad.Failable -- | The Failable class. A Monad which is an instance of this class -- can be used as a context in a function running in one with this class -- constraint, in order to report error conditions class (Monad m) => Failable m -- | trigger a failure. It takes an exception value as argument and it -- returns whatever might be used to abort a monadic computation in the -- monad instantiating this class. failure :: (Failable m, Exception e) => e -> m a -- | recover from a possible failure. Basically a generalized -- catch for a Failable. recover :: (Failable m, e ~ SomeException) => m a -> (e -> m a) -> m a -- | Perform a set of IO actions in a Failable MonadIO -- instance, triggering a failure upon an IO exception, instead of -- blindly triggering an asynchronos exception. This serves ultimately to -- unify error handling in the Failable context. For example: -- --
--   foo :: (Failable m, MonadIO m) => m ()
--   foo = do
--     failableIO $ do
--       txt <- readFile "foo.txt"
--       putStrLn txt
--   
-- --
--   >>> λ> runExceptT foo
--   
--   >>> Left foo.txt: openFile: does not exist (No such file or directory)
--   
--   >>> 
--   
--   >>> λ> runMaybeT foo
--   
--   >>> Nothing
--   
--   >>> 
--   
--   >>> λ> foo
--   
--   >>> *** Exception: foo.txt: openFile: does not exist (No such file or directory)
--   
failableIO :: (Failable m, MonadIO m) => IO a -> m a -- | Promote an Either value into a Failable context. -- Useful to reduce verbosity when using functions that return an -- Either type. If the value is Left err, the wrapped -- error is then passed as an argument to the provided function which -- should return an instance of Exception. so for example: -- --
--   data MyErrors = BadValue deriving (Typeable, Show)
--   instance Exception MyErrors
--   
--   foo :: (Failable m) => String -> m Int
--   foo = hoistEither BadValue . readEither
--   
-- --
--   >>> λ> foo "5" :: Maybe Int
--   
--   >>> Just 5
--   
--   >>> λ> foo "5" :: Either SomeException Int
--   
--   >>> Right 5
--   
--   >>> λ> foo "X5" :: Either SomeException Int
--   
--   >>> Left (BadValue "Prelude.read: no parse")
--   
--   >>> λ> foo "5" :: Maybe Int
--   
--   >>> Just 5
--   
--   >>> λ> foo "X5" :: Maybe Int
--   
--   >>> Nothing
--   
hoistEither :: (Failable m, Exception e) => (a -> e) -> Either a b -> m b -- | Promote a Maybe into a Failable context. Useful -- to reduce boilerplate when using functions that might return a -- Maybe type. If the value is Nothing, the error -- specified is then triggered in the Failable context hoistMaybe :: (Failable m, Exception e) => e -> Maybe a -> m a instance Control.Monad.Failable.Failable GHC.Types.IO instance Control.Monad.Failable.Failable [] instance Control.Monad.Failable.Failable GHC.Maybe.Maybe instance (e Data.Type.Equality.~ GHC.Exception.Type.SomeException) => Control.Monad.Failable.Failable (Data.Either.Either e) instance GHC.Base.Monad m => Control.Monad.Failable.Failable (Control.Monad.Trans.Maybe.MaybeT m) instance (GHC.Base.Monad m, e Data.Type.Equality.~ GHC.Exception.Type.SomeException) => Control.Monad.Failable.Failable (Control.Monad.Trans.Except.ExceptT e m) instance GHC.Exception.Type.Exception ()