W3cubDocs

/Haskell 9

Control.Monad.Trans.Except

Copyright (C) 2013 Ross Paterson
License BSD-style (see the file LICENSE)
Maintainer [email protected]
Stability experimental
Portability portable
Safe Haskell Safe
Language Haskell2010

Description

This monad transformer extends a monad with the ability to throw and catch exceptions.

A sequence of actions terminates normally, producing a value, only if none of the actions in the sequence throws an exception. If one throws an exception, the rest of the sequence is skipped and the composite action exits with that exception.

If the value of the exception is not required, the variant in Control.Monad.Trans.Maybe may be used instead.

The Except monad

type Except e = ExceptT e Identity Source

The parameterizable exception monad.

Computations are either exceptions (of any type) or normal values. These computations are plain values, and are unrelated to the Control.Exception mechanism, which is tied to the IO monad.

The return function returns a normal value, while >>= exits on the first exception. For a variant that continues after an error and collects all the errors, see Errors.

except :: forall (m :: Type -> Type) e a. Monad m => Either e a -> ExceptT e m a Source

Constructor for computations in the exception monad. (The inverse of runExcept).

runExcept :: Except e a -> Either e a Source

Extractor for computations in the exception monad. (The inverse of except).

mapExcept :: (Either e a -> Either e' b) -> Except e a -> Except e' b Source

Map the unwrapped computation using the given function.

withExcept :: (e -> e') -> Except e a -> Except e' a Source

Transform any exceptions thrown by the computation using the given function (a specialization of withExceptT).

The ExceptT monad transformer

newtype ExceptT e (m :: Type -> Type) a Source

A monad transformer that adds exceptions to other monads.

ExceptT constructs a monad parameterized over two things:

  • e - An arbitrary exception type.
  • m - The inner monad.

The monadic computations are a plain values. They are unrelated to the Control.Exception mechanism, which is tied to the IO monad.

The return function yields a computation that produces the given value, while >>= sequences two subcomputations, exiting on the first exception.

Constructors

ExceptT (m (Either e a))
Instances
Instances details
Functor m => Generic1 (ExceptT e m :: Type -> Type) Source
Instance details

Defined in Control.Monad.Trans.Except

Associated Types

type Rep1 (ExceptT e m :: Type -> Type)
Instance details

Defined in Control.Monad.Trans.Except

type Rep1 (ExceptT e m :: Type -> Type) = D1 ('MetaData "ExceptT" "Control.Monad.Trans.Except" "transformers-0.6.1.2-72bd" 'True) (C1 ('MetaCons "ExceptT" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 (Either e))))

Methods

from1 :: ExceptT e m a -> Rep1 (ExceptT e m) a

to1 :: Rep1 (ExceptT e m) a -> ExceptT e m a

MonadTrans (ExceptT e) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

lift :: Monad m => m a -> ExceptT e m a Source

(Eq e, Eq1 m) => Eq1 (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftEq :: (a -> b -> Bool) -> ExceptT e m a -> ExceptT e m b -> Bool Source

(Ord e, Ord1 m) => Ord1 (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftCompare :: (a -> b -> Ordering) -> ExceptT e m a -> ExceptT e m b -> Ordering Source

(Read e, Read1 m) => Read1 (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (ExceptT e m a) Source

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [ExceptT e m a] Source

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (ExceptT e m a) Source

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [ExceptT e m a] Source

(Show e, Show1 m) => Show1 (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ExceptT e m a -> ShowS Source

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ExceptT e m a] -> ShowS Source

Contravariant m => Contravariant (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

contramap :: (a' -> a) -> ExceptT e m a -> ExceptT e m a' Source

(>$) :: b -> ExceptT e m b -> ExceptT e m a Source

(Functor m, Monad m, Monoid e) => Alternative (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

empty :: ExceptT e m a

(<|>) :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a

some :: ExceptT e m a -> ExceptT e m [a]

many :: ExceptT e m a -> ExceptT e m [a]

(Functor m, Monad m) => Applicative (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

pure :: a -> ExceptT e m a

(<*>) :: ExceptT e m (a -> b) -> ExceptT e m a -> ExceptT e m b

liftA2 :: (a -> b -> c) -> ExceptT e m a -> ExceptT e m b -> ExceptT e m c

(*>) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m b

(<*) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m a

Functor m => Functor (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

fmap :: (a -> b) -> ExceptT e m a -> ExceptT e m b

(<$) :: a -> ExceptT e m b -> ExceptT e m a

Monad m => Monad (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

(>>=) :: ExceptT e m a -> (a -> ExceptT e m b) -> ExceptT e m b

(>>) :: ExceptT e m a -> ExceptT e m b -> ExceptT e m b

return :: a -> ExceptT e m a

(Monad m, Monoid e) => MonadPlus (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

mzero :: ExceptT e m a

mplus :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a

MonadFail m => MonadFail (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

fail :: String -> ExceptT e m a

MonadFix m => MonadFix (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

mfix :: (a -> ExceptT e m a) -> ExceptT e m a

MonadIO m => MonadIO (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftIO :: IO a -> ExceptT e m a

MonadZip m => MonadZip (ExceptT e m) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

mzip :: ExceptT e m a -> ExceptT e m b -> ExceptT e m (a, b)

mzipWith :: (a -> b -> c) -> ExceptT e m a -> ExceptT e m b -> ExceptT e m c

munzip :: ExceptT e m (a, b) -> (ExceptT e m a, ExceptT e m b)

Foldable f => Foldable (ExceptT e f) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

fold :: Monoid m => ExceptT e f m -> m

foldMap :: Monoid m => (a -> m) -> ExceptT e f a -> m

foldMap' :: Monoid m => (a -> m) -> ExceptT e f a -> m

foldr :: (a -> b -> b) -> b -> ExceptT e f a -> b

foldr' :: (a -> b -> b) -> b -> ExceptT e f a -> b

foldl :: (b -> a -> b) -> b -> ExceptT e f a -> b

foldl' :: (b -> a -> b) -> b -> ExceptT e f a -> b

foldr1 :: (a -> a -> a) -> ExceptT e f a -> a

foldl1 :: (a -> a -> a) -> ExceptT e f a -> a

toList :: ExceptT e f a -> [a]

null :: ExceptT e f a -> Bool

length :: ExceptT e f a -> Int

elem :: Eq a => a -> ExceptT e f a -> Bool

maximum :: Ord a => ExceptT e f a -> a

minimum :: Ord a => ExceptT e f a -> a

sum :: Num a => ExceptT e f a -> a

product :: Num a => ExceptT e f a -> a

Traversable f => Traversable (ExceptT e f) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

traverse :: Applicative f0 => (a -> f0 b) -> ExceptT e f a -> f0 (ExceptT e f b)

sequenceA :: Applicative f0 => ExceptT e f (f0 a) -> f0 (ExceptT e f a)

mapM :: Monad m => (a -> m b) -> ExceptT e f a -> m (ExceptT e f b)

sequence :: Monad m => ExceptT e f (m a) -> m (ExceptT e f a)

Generic (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

Associated Types

type Rep (ExceptT e m a)
Instance details

Defined in Control.Monad.Trans.Except

type Rep (ExceptT e m a) = D1 ('MetaData "ExceptT" "Control.Monad.Trans.Except" "transformers-0.6.1.2-72bd" 'True) (C1 ('MetaCons "ExceptT" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Either e a)))))

Methods

from :: ExceptT e m a -> Rep (ExceptT e m a) x

to :: Rep (ExceptT e m a) x -> ExceptT e m a

(Read e, Read1 m, Read a) => Read (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

readsPrec :: Int -> ReadS (ExceptT e m a)

readList :: ReadS [ExceptT e m a]

readPrec :: ReadPrec (ExceptT e m a)

readListPrec :: ReadPrec [ExceptT e m a]

(Show e, Show1 m, Show a) => Show (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

showsPrec :: Int -> ExceptT e m a -> ShowS

show :: ExceptT e m a -> String

showList :: [ExceptT e m a] -> ShowS

(Eq e, Eq1 m, Eq a) => Eq (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

(==) :: ExceptT e m a -> ExceptT e m a -> Bool

(/=) :: ExceptT e m a -> ExceptT e m a -> Bool

(Ord e, Ord1 m, Ord a) => Ord (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

Methods

compare :: ExceptT e m a -> ExceptT e m a -> Ordering

(<) :: ExceptT e m a -> ExceptT e m a -> Bool

(<=) :: ExceptT e m a -> ExceptT e m a -> Bool

(>) :: ExceptT e m a -> ExceptT e m a -> Bool

(>=) :: ExceptT e m a -> ExceptT e m a -> Bool

max :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a

min :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a

type Rep1 (ExceptT e m :: Type -> Type) Source
Instance details

Defined in Control.Monad.Trans.Except

type Rep1 (ExceptT e m :: Type -> Type) = D1 ('MetaData "ExceptT" "Control.Monad.Trans.Except" "transformers-0.6.1.2-72bd" 'True) (C1 ('MetaCons "ExceptT" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 (Either e))))
type Rep (ExceptT e m a) Source
Instance details

Defined in Control.Monad.Trans.Except

type Rep (ExceptT e m a) = D1 ('MetaData "ExceptT" "Control.Monad.Trans.Except" "transformers-0.6.1.2-72bd" 'True) (C1 ('MetaCons "ExceptT" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Either e a)))))

runExceptT :: ExceptT e m a -> m (Either e a) Source

The inverse of ExceptT.

mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b Source

Map the unwrapped computation using the given function.

withExceptT :: forall (m :: Type -> Type) e e' a. Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a Source

Transform any exceptions thrown by the computation using the given function.

Exception operations

throwE :: forall (m :: Type -> Type) e a. Monad m => e -> ExceptT e m a Source

Signal an exception value e.

catchE Source

Arguments

:: forall (m :: Type -> Type) e a e'. Monad m
=> ExceptT e m a

the inner computation

-> (e -> ExceptT e' m a)

a handler for exceptions in the inner computation

-> ExceptT e' m a

Handle an exception.

handleE :: forall (m :: Type -> Type) e e' a. Monad m => (e -> ExceptT e' m a) -> ExceptT e m a -> ExceptT e' m a Source

The same as flip catchE, which is useful in situations where the code for the handler is shorter.

tryE :: forall (m :: Type -> Type) e a. Monad m => ExceptT e m a -> ExceptT e m (Either e a) Source

Similar to catchE, but returns an Either result which is (Right a) if no exception was thown, or (Left ex) if an exception ex was thrown.

finallyE :: forall (m :: Type -> Type) e a. Monad m => ExceptT e m a -> ExceptT e m () -> ExceptT e m a Source

finallyE a b executes computation a followed by computation b, even if a exits early by throwing an exception. In the latter case, the exception is re-thrown after b has been executed.

Lifting other operations

liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ExceptT e m) a b Source

Lift a callCC operation to the new monad.

liftListen :: Monad m => Listen w m (Either e a) -> Listen w (ExceptT e m) a Source

Lift a listen operation to the new monad.

liftPass :: Monad m => Pass w m (Either e a) -> Pass w (ExceptT e m) a Source

Lift a pass operation to the new monad.

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/9.12.1/docs/libraries/transformers-0.6.1.2-72bd/Control-Monad-Trans-Except.html