Copyright | (c) Eitan Chatav, 2015 |
---|---|
License | PublicDomain |
Maintainer | eitan.chatav@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
The EitherContT
type and API provide an idiomatic way to handle errors in
continuation passing style over some base monad.
- newtype EitherContT a l m r = EitherContT {
- runEitherContT :: (l -> m a) -> (r -> m a) -> m a
- liftEitherT :: Monad m => EitherT l m r -> EitherContT a l m r
- fmapL :: (l -> l') -> EitherContT a l m r -> EitherContT a l' m r
- bimapEC :: (l -> l') -> (r -> r') -> EitherContT a l m r -> EitherContT a l' m r'
- throwEC :: l -> EitherContT a l m r
- apL :: EitherContT a (l -> l') m r -> EitherContT a l m r -> EitherContT a l' m r
- catchEC :: EitherContT a l m r -> (l -> EitherContT a l' m r) -> EitherContT a l' m r
- handleEC :: (l -> EitherContT a l' m r) -> EitherContT a l m r -> EitherContT a l' m r
- (<?<) :: (l' -> EitherContT a l'' m r) -> (l -> EitherContT a l' m r) -> l -> EitherContT a l'' m r
- (>?>) :: (l -> EitherContT a l' m r) -> (l' -> EitherContT a l'' m r) -> l -> EitherContT a l'' m r
- liftL :: Monad m => m l -> EitherContT a l m r
- flipEC :: EitherContT a l m r -> EitherContT a r m l
- mapEitherContT :: (m a -> m a) -> EitherContT a l m r -> EitherContT a l m r
- withEitherContTR :: ((r' -> m a) -> r -> m a) -> EitherContT a l m r -> EitherContT a l m r'
- withEitherContTL :: ((l' -> m a) -> l -> m a) -> EitherContT a l m r -> EitherContT a l' m r
- callCCL :: ((l -> EitherContT a l' m r) -> EitherContT a l m r) -> EitherContT a l m r
- lowerMonadError :: MonadError l m => EitherContT r l m r -> m r
- liftMonadError :: MonadError l m => m r -> EitherContT a l m r
Documentation
newtype EitherContT a l m r Source
The EitherContT
a
l
m
r
type encodes a sum type monad transformer
in continuation passing style which is separately monadic in both l
and
r
. Interestingly, this property holds for any type constructor m
.
EitherContT | Construct a continuation-passing computation from a function. |
|
MonadError l (EitherContT a l m) | The |
MonadTrans (EitherContT a l) |
|
Monad (EitherContT a l m) | The |
Functor (EitherContT a l m) | The |
Applicative (EitherContT a l m) | The |
MonadCont (EitherContT a l m) | Call with current success continuation. |
liftEitherT :: Monad m => EitherT l m r -> EitherContT a l m r Source
liftEitherT
embeds EitherT
in EitherContT
a
.
fmapL :: (l -> l') -> EitherContT a l m r -> EitherContT a l' m r Source
fmapL
encodes functoriality of EitherContT
a
l
m
r
in l
.
bimapEC :: (l -> l') -> (r -> r') -> EitherContT a l m r -> EitherContT a l' m r' Source
bimapEC
encodes bifunctoriality of EitherContT
a
l
m
r
in l
and r
.
bimapEC f id = fmapL f
bimapEC id f = fmap f
throwEC :: l -> EitherContT a l m r Source
throwEC
encodes the applicative/monadic unit of EitherContT
a
l
m
r
in l
.
apL :: EitherContT a (l -> l') m r -> EitherContT a l m r -> EitherContT a l' m r Source
apL
encodes applicativity of EitherContT
a
l
m
r
in l
.
catchEC :: EitherContT a l m r -> (l -> EitherContT a l' m r) -> EitherContT a l' m r Source
handleEC :: (l -> EitherContT a l' m r) -> EitherContT a l m r -> EitherContT a l' m r Source
(<?<) :: (l' -> EitherContT a l'' m r) -> (l -> EitherContT a l' m r) -> l -> EitherContT a l'' m r Source
A right-to-left, point free way to compose handlers. The monad laws look
more elegant, expressed in terms of <?<
.
throwEC <?< f = f = f <?< throwEC
(h <?< g) <?< f = h <?< (g <?< f)
(>?>) :: (l -> EitherContT a l' m r) -> (l' -> EitherContT a l'' m r) -> l -> EitherContT a l'' m r Source
A left-to-right, point free way to compose handlers.
liftL :: Monad m => m l -> EitherContT a l m r Source
EitherContT
a
l
m
r
is a monad transformer for m
in l
.
flipEC :: EitherContT a l m r -> EitherContT a r m l Source
flipEC
encodes the symmetry of l
and r
in EitherContT
a
l
m
r
.
flipEC . flipEC = id
mapEitherContT :: (m a -> m a) -> EitherContT a l m r -> EitherContT a l m r Source
Apply a function to transform the result of a continuation-passing computation.
withEitherContTR :: ((r' -> m a) -> r -> m a) -> EitherContT a l m r -> EitherContT a l m r' Source
Apply a function to transform the success continuation passed to a continuation-passing computation.
withEitherContTL :: ((l' -> m a) -> l -> m a) -> EitherContT a l m r -> EitherContT a l' m r Source
Apply a function to transform the failure continuation passed to an continuation-passing computation.
callCCL :: ((l -> EitherContT a l' m r) -> EitherContT a l m r) -> EitherContT a l m r Source
Call with current failure continuation.
lowerMonadError :: MonadError l m => EitherContT r l m r -> m r Source
lowerMonadError
runs the continuation-passing computation, throwing on
failure and returning on success.
liftMonadError :: MonadError l m => m r -> EitherContT a l m r Source
liftMonadError
embeds a MonadError
computation m
r
into
EitherContT
a
l
m
r
.
liftMonadError
and lowerMonadError
are
one-sided inverses, making MonadError l m => m r
a retract of
EitherContT
r
l
m
r
.
lowerMonadError . liftMonadError = id