either-result-0.3.0.0: ‘MonadFail’ instance for a wrapper of ‘ExceptT String m a’.

Safe HaskellNone
LanguageHaskell2010
Extensions
  • TypeSynonymInstances
  • FlexibleContexts
  • FlexibleInstances
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • ExplicitNamespaces
  • PatternSynonyms

Control.Monad.Result

Contents

Description

This monad transformer extends a monad with the ability to fail.

Synopsis

The class

class Monad m => MonadError e (m :: Type -> Type) | m -> e where #

The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.

Is parameterized over the type of error information and the monad type constructor. It is common to use Either String as the monad type constructor for an error monad in which error descriptions take the form of strings. In that case and many other common cases the resulting monad is already defined as an instance of the MonadError class. You can also define your own error type and/or use a monad type constructor other than Either String or Either IOError. In these cases you will have to explicitly define instances of the MonadError class. (If you are using the deprecated Control.Monad.Error or Control.Monad.Trans.Error, you may also have to define an Error instance.)

Methods

throwError :: e -> m a #

Is used within a monadic computation to begin exception processing.

catchError :: m a -> (e -> m a) -> m a #

A handler function to handle previous errors and return to normal execution. A common idiom is:

do { action1; action2; action3 } `catchError` handler

where the action functions can call throwError. Note that handler and the do-block must have the same return type.

Instances
MonadError () Maybe

Since: mtl-2.2.2

Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: () -> Maybe a #

catchError :: Maybe a -> (() -> Maybe a) -> Maybe a #

MonadError IOException IO 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: IOException -> IO a #

catchError :: IO a -> (IOException -> IO a) -> IO a #

MonadError e m => MonadError e (MaybeT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> MaybeT m a #

catchError :: MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a #

MonadError e m => MonadError e (ListT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ListT m a #

catchError :: ListT m a -> (e -> ListT m a) -> ListT m a #

MonadError e (Either e) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> Either e a #

catchError :: Either e a -> (e -> Either e a) -> Either e a #

Monad m => MonadError String (ResultT m) Source # 
Instance details

Defined in Control.Monad.Result

Methods

throwError :: String -> ResultT m a #

catchError :: ResultT m a -> (String -> ResultT m a) -> ResultT m a #

(Monoid w, MonadError e m) => MonadError e (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> WriterT w m a #

catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a #

(Monoid w, MonadError e m) => MonadError e (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> WriterT w m a #

catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a #

MonadError e m => MonadError e (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> StateT s m a #

catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a #

MonadError e m => MonadError e (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> StateT s m a #

catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a #

MonadError e m => MonadError e (IdentityT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> IdentityT m a #

catchError :: IdentityT m a -> (e -> IdentityT m a) -> IdentityT m a #

Monad m => MonadError e (ExceptT e m)

Since: mtl-2.2

Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ExceptT e m a #

catchError :: ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a #

(Monad m, Error e) => MonadError e (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ErrorT e m a #

catchError :: ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m a #

MonadError e m => MonadError e (ReaderT r m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ReaderT r m a #

catchError :: ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a #

(Monoid w, MonadError e m) => MonadError e (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> RWST r w s m a #

catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a #

(Monoid w, MonadError e m) => MonadError e (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> RWST r w s m a #

catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a #

The ResultT monad transformer

data ResultT m a where Source #

A monad transformer that is similar to ExceptT except a MonadFail instance.

MonadFail = ResultT . throwE

Bundled Patterns

pattern ResultT :: Functor m => m (Result a) -> ResultT m a

Construct and destruct Result.

Instances
MonadTrans ResultT Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

lift :: Monad m => m a -> ResultT m a #

Monad m => MonadError String (ResultT m) Source # 
Instance details

Defined in Control.Monad.Result

Methods

throwError :: String -> ResultT m a #

catchError :: ResultT m a -> (String -> ResultT m a) -> ResultT m a #

Monad m => Monad (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

(>>=) :: ResultT m a -> (a -> ResultT m b) -> ResultT m b #

(>>) :: ResultT m a -> ResultT m b -> ResultT m b #

return :: a -> ResultT m a #

fail :: String -> ResultT m a #

Functor m => Functor (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

fmap :: (a -> b) -> ResultT m a -> ResultT m b #

(<$) :: a -> ResultT m b -> ResultT m a #

Read a => Read (Result a) Source # 
Instance details

Defined in Control.Monad.Trans.Result

Show a => Show (Result a) Source # 
Instance details

Defined in Control.Monad.Trans.Result

Methods

showsPrec :: Int -> Result a -> ShowS #

show :: Result a -> String #

showList :: [Result a] -> ShowS #

MonadFix m => MonadFix (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

mfix :: (a -> ResultT m a) -> ResultT m a #

Monad m => MonadFail (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

fail :: String -> ResultT m a #

Monad m => Applicative (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

pure :: a -> ResultT m a #

(<*>) :: ResultT m (a -> b) -> ResultT m a -> ResultT m b #

liftA2 :: (a -> b -> c) -> ResultT m a -> ResultT m b -> ResultT m c #

(*>) :: ResultT m a -> ResultT m b -> ResultT m b #

(<*) :: ResultT m a -> ResultT m b -> ResultT m a #

Foldable m => Foldable (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

fold :: Monoid m0 => ResultT m m0 -> m0 #

foldMap :: Monoid m0 => (a -> m0) -> ResultT m a -> m0 #

foldr :: (a -> b -> b) -> b -> ResultT m a -> b #

foldr' :: (a -> b -> b) -> b -> ResultT m a -> b #

foldl :: (b -> a -> b) -> b -> ResultT m a -> b #

foldl' :: (b -> a -> b) -> b -> ResultT m a -> b #

foldr1 :: (a -> a -> a) -> ResultT m a -> a #

foldl1 :: (a -> a -> a) -> ResultT m a -> a #

toList :: ResultT m a -> [a] #

null :: ResultT m a -> Bool #

length :: ResultT m a -> Int #

elem :: Eq a => a -> ResultT m a -> Bool #

maximum :: Ord a => ResultT m a -> a #

minimum :: Ord a => ResultT m a -> a #

sum :: Num a => ResultT m a -> a #

product :: Num a => ResultT m a -> a #

Traversable m => Traversable (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

traverse :: Applicative f => (a -> f b) -> ResultT m a -> f (ResultT m b) #

sequenceA :: Applicative f => ResultT m (f a) -> f (ResultT m a) #

mapM :: Monad m0 => (a -> m0 b) -> ResultT m a -> m0 (ResultT m b) #

sequence :: Monad m0 => ResultT m (m0 a) -> m0 (ResultT m a) #

Semigroup (Result a) Source # 
Instance details

Defined in Control.Monad.Trans.Result

Methods

(<>) :: Result a -> Result a -> Result a #

sconcat :: NonEmpty (Result a) -> Result a #

stimes :: Integral b => b -> Result a -> Result a #

Monoid (Result a) Source # 
Instance details

Defined in Control.Monad.Trans.Result

Methods

mempty :: Result a #

mappend :: Result a -> Result a -> Result a #

mconcat :: [Result a] -> Result a #

Contravariant m => Contravariant (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

contramap :: (a -> b) -> ResultT m b -> ResultT m a #

(>$) :: b -> ResultT m b -> ResultT m a #

Eq1 m => Eq1 (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

liftEq :: (a -> b -> Bool) -> ResultT m a -> ResultT m b -> Bool #

Ord1 m => Ord1 (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

liftCompare :: (a -> b -> Ordering) -> ResultT m a -> ResultT m b -> Ordering #

Read1 m => Read1 (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (ResultT m a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [ResultT m a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (ResultT m a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [ResultT m a] #

Show1 m => Show1 (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ResultT m a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ResultT m a] -> ShowS #

MonadZip m => MonadZip (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

mzip :: ResultT m a -> ResultT m b -> ResultT m (a, b) #

mzipWith :: (a -> b -> c) -> ResultT m a -> ResultT m b -> ResultT m c #

munzip :: ResultT m (a, b) -> (ResultT m a, ResultT m b) #

MonadIO m => MonadIO (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

liftIO :: IO a -> ResultT m a #

Monad m => Alternative (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

empty :: ResultT m a #

(<|>) :: ResultT m a -> ResultT m a -> ResultT m a #

some :: ResultT m a -> ResultT m [a] #

many :: ResultT m a -> ResultT m [a] #

Monad m => MonadPlus (ResultT m) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

mzero :: ResultT m a #

mplus :: ResultT m a -> ResultT m a -> ResultT m a #

(Eq1 m, Eq a) => Eq (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

(==) :: ResultT m a -> ResultT m a -> Bool #

(/=) :: ResultT m a -> ResultT m a -> Bool #

(Ord1 m, Ord a) => Ord (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

compare :: ResultT m a -> ResultT m a -> Ordering #

(<) :: ResultT m a -> ResultT m a -> Bool #

(<=) :: ResultT m a -> ResultT m a -> Bool #

(>) :: ResultT m a -> ResultT m a -> Bool #

(>=) :: ResultT m a -> ResultT m a -> Bool #

max :: ResultT m a -> ResultT m a -> ResultT m a #

min :: ResultT m a -> ResultT m a -> ResultT m a #

(Read1 m, Read a) => Read (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

(Show1 m, Show a) => Show (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Methods

showsPrec :: Int -> ResultT m a -> ShowS #

show :: ResultT m a -> String #

showList :: [ResultT m a] -> ShowS #

Generic (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

Associated Types

type Rep (ResultT m a) :: Type -> Type #

Methods

from :: ResultT m a -> Rep (ResultT m a) x #

to :: Rep (ResultT m a) x -> ResultT m a #

type Rep (ResultT m a) Source # 
Instance details

Defined in Control.Monad.Trans.Except.Result

type Rep (ResultT m a) = D1 (MetaData "ResultT" "Control.Monad.Trans.Except.Result" "either-result-0.3.0.0-2MdrAYLaj1r9H6Nl4angWI" True) (C1 (MetaCons "ResultT" PrefixI True) (S1 (MetaSel (Just "runResultT") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ExceptT String m a))))

runResultT :: Functor m => ResultT m a -> m (Result a) Source #

Unwrap ResultT.

mapResultT :: (Functor m, Functor n) => (m (Result a) -> n (Result b)) -> ResultT m a -> ResultT n b Source #

Map the unwrapped computation using the given function.

The Result monad

type Result = ResultT Identity Source #

A result monad.

pattern Result :: Either String a -> Result a Source #

Wrap Result a.

pattern Error :: String -> Result a Source #

Error means errors and failures etc.

pattern Success :: a -> Result a Source #

Success means successes and OKs etc.

result :: (String -> b) -> (a -> b) -> Result a -> b Source #

Case analysis for the Result type.

Examples

Expand
>>> let s = Success 0
>>> let e = Error "critical"
>>> result ("Bad: " ++) (("OK: " ++) . show) s
"OK: 0"
>>> result ("Bad: " ++) (("OK: " ++) . show) e
"Bad: critical"

fromSuccess :: a -> Result a -> a Source #

Convert Result a to a with a default value.

toMonadFail :: MonadFail m => Result a -> m a Source #

Convert Result a to MonadFail m => m a.

Re-exports

Orphan instances

Monad m => MonadError String (ResultT m) Source # 
Instance details

Methods

throwError :: String -> ResultT m a #

catchError :: ResultT m a -> (String -> ResultT m a) -> ResultT m a #