10 -- * The ExceptT monad transformer
14 -- * MonadExcept class (implicit)
18 -- * The Except monad (implicit)
21 -- * The ExceptT monad transformer (implicit)
30import qualified Control.Monad.Except as T
31import Control.Monad.Signatures (Catch)
32import qualified Control.Monad.Trans.Lift.Catch as Lift
34import Data.Functor.Identity
36import Ether.TaggedTrans
39class Monad m => MonadExcept tag e m | m tag -> e where
41 -- | Is used within a monadic computation to begin exception processing.
44 -- | A TaggedTrans function to handle previous exceptions and return to
46 catch :: m a -> (e -> m a) -> m a
48instance {-# OVERLAPPABLE #-}
52 ) => MonadExcept tag e (t m) where
54 throw = Lift.lift . throw @tag
57 catch = Lift.liftCatch (catch @tag)
60-- | Encode type-level information for 'ExceptT'.
63-- | The parameterizable exception monad.
65-- Computations are either exceptions or normal values.
67-- The 'return' function returns a normal value, while '>>=' exits on
68-- the first exception.
69type Except tag e = ExceptT tag e Identity
71-- | The exception monad transformer.
73-- The 'return' function returns a normal value, while '>>=' exits on
74-- the first exception.
75type ExceptT tag e = TaggedTrans (TAGGED EXCEPT tag) (T.ExceptT e)
77-- | Runs an 'Except' and returns either an exception or a normal value.
78runExcept :: forall tag e a . Except tag e a -> Either e a
79runExcept = coerce (T.runExcept @e @a)
80{-# INLINE runExcept #-}
82-- | Runs an 'ExceptT' and returns either an exception or a normal value.
83runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
84runExceptT = coerce (T.runExceptT @e @m @a)
85{-# INLINE runExceptT #-}
87-- | Constructor for computations in the exception monad transformer.
88exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
89exceptT = coerce (T.ExceptT @e @m @a)
92type instance HandleSuper EXCEPT e trans = ()
93type instance HandleConstraint EXCEPT e trans m =
94 T.MonadError e (trans m)
96instance Handle EXCEPT e (T.ExceptT e) where
98 {-# INLINE handling #-}
101 ( Handle EXCEPT e trans
102 , Monad m, Monad (trans m)
103 ) => MonadExcept tag e (TaggedTrans (TAGGED EXCEPT tag) trans m)
106 handling @EXCEPT @e @trans @m $
107 coerce (T.throwError @e @(trans m) @a) ::
108 forall eff a . e -> TaggedTrans eff trans m a
112 handling @EXCEPT @e @trans @m $
113 coerce (T.catchError @e @(trans m) @a) ::
114 forall eff a . Catch e (TaggedTrans eff trans m) a
117type MonadExcept' e = MonadExcept e e
119throw' :: forall e m a . MonadExcept' e m => e -> m a
123catch' :: forall e m a . MonadExcept' e m => m a -> (e -> m a) -> m a
127type Except' e = Except e e
129runExcept' :: Except' e a -> Either e a
130runExcept' = runExcept
131{-# INLINE runExcept' #-}
133type ExceptT' e = ExceptT e e
135exceptT' :: m (Either e a) -> ExceptT' e m a
137{-# INLINE exceptT' #-}
139runExceptT' :: ExceptT' e m a -> m (Either e a)
140runExceptT' = runExceptT
141{-# INLINE runExceptT' #-}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list