Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides an InterposeC
carrier capable of "eavesdropping" on requests
made to other carriers. This is a useful capability for dynamism in deeply-nested
effect stacks, but can lead to complicated control flow. Be careful.
Synopsis
- newtype InterposeC eff m a = InterposeC {
- runInterposeC :: ReaderC (Handler eff m) m a
- runInterpose :: (forall x. eff m x -> m x) -> InterposeC eff m a -> m a
Documentation
newtype InterposeC eff m a Source #
InterposeC | |
|
Instances
runInterpose :: (forall x. eff m x -> m x) -> InterposeC eff m a -> m a Source #
runInterpose
takes a handler for a given effect (such as State
or Reader
)
and runs that handler whenever an effect of that type is encountered. Within a
handler you can use all the capabilities of the underlying monad stack, including
the intercepted effect, and you can pass the effect on to the original handler
using send
.
run . evalState @Int a . runInterpose @(State Int) (\op -> modify @Int (+b) *> send op) $ modify @Int (+b) === a + b + b