Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class MonadEffect (Signal a b) m => MonadEffectSignal a b m | m a -> b where
- data ResumeOrBreak b c
- throwSignal :: Throws a m => a -> m b
- handleSignal :: Monad m => (a -> m (ResumeOrBreak b c)) -> EffectHandler (Signal a b) (ExceptT c m) c -> m c
- handleAsException :: Monad m => (a -> m c) -> EffectHandler (Signal a b) (ExceptT c m) c -> m c
- type Throws e m = MonadEffectSignal e Void m
- handleException :: Monad m => (a -> m c) -> ExceptT a m c -> m c
- handleToEither :: ExceptT e m a -> m (Either e a)
- module Control.Effects
- module Control.Monad.Trans.Except
- newtype MaybeT m a :: (* -> *) -> * -> * = MaybeT {}
- discardAllExceptions :: MaybeT m a -> m (Maybe a)
- showAllExceptions :: Functor m => ExceptT SomeSignal m a -> m (Either Text a)
Documentation
class MonadEffect (Signal a b) m => MonadEffectSignal a b m | m a -> b where Source #
This class allows you to "throw" a signal. For the most part signals are the same as checked exceptions. The difference here is that the handler has the option to provide the value that will be the result _of calling the signal function_. This effectibvely allows you to have recoverable exceptions at the call site, instead of just at the handling site.
This class can be considered an alias for MonadEffect (Signal a b)
so your code isn't
required to provide any instances.
There are no restrictions on the type of values that can be thrown or returned.
(MonadEffectSignal a b m, MonadTrans t, Monad (t m)) => MonadEffectSignal a b (t m) Source # | |
Monad m => MonadEffectSignal a Void (MaybeT m) Source # | |
Monad m => MonadEffectSignal e Void (ExceptT e m) Source # | |
data ResumeOrBreak b c Source #
The handle function will return a value of this type.
throwSignal :: Throws a m => a -> m b Source #
Throw a signal with no possible recovery. The handler is forced to only return the Break
constructor because it cannot construct a Void
value.
If this function is used along with handleAsException
, this module behaves like regular
checked exceptions.
handleSignal :: Monad m => (a -> m (ResumeOrBreak b c)) -> EffectHandler (Signal a b) (ExceptT c m) c -> m c Source #
Handle signals of a computation. The handler function has the option to provide a value
to the caller of signal
and continue execution there, or do what regular exception handlers
do and continue execution after the handler.
handleAsException :: Monad m => (a -> m c) -> EffectHandler (Signal a b) (ExceptT c m) c -> m c Source #
This handler can only behave like a regular exception handler. If used along with throwSignal
this module behaves like regular checked exceptions.
type Throws e m = MonadEffectSignal e Void m Source #
handleException :: Monad m => (a -> m c) -> ExceptT a m c -> m c Source #
In case only throwSignal
is used then the function signatures will have a
constraint or, equivalently, a Throws
a m
constraint. In those cases you
can use this function to handle their exceptions. This function will not work for handing other
signals because MonadEffectSignal
a Void mExceptT
doesn't satisfy other constraints.
The advantage of using this handler is that your inferred transformer stack will have one less layer which can potentially lead to slight performance increases.
handleToEither :: ExceptT e m a -> m (Either e a) Source #
See documentation for handleException
. This handler gives you an Either
.
module Control.Effects
module Control.Monad.Trans.Except
newtype MaybeT m a :: (* -> *) -> * -> * #
The parameterizable maybe monad, obtained by composing an arbitrary
monad with the Maybe
monad.
Computations are actions that may produce a value or exit.
The return
function yields a computation that produces that
value, while >>=
sequences two subcomputations, exiting if either
computation does.
discardAllExceptions :: MaybeT m a -> m (Maybe a) Source #