fused-effects-0.4.0.0: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Interpose

Description

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

Documentation

newtype InterposeC eff m a Source #

Constructors

InterposeC 

Fields

Instances
(HFunctor eff, Carrier sig m, Member eff sig) => Carrier sig (InterposeC eff m) Source # 
Instance details

Defined in Control.Effect.Interpose

Methods

eff :: sig (InterposeC eff m) (InterposeC eff m a) -> InterposeC eff m a Source #

MonadTrans (InterposeC eff) Source # 
Instance details

Defined in Control.Effect.Interpose

Methods

lift :: Monad m => m a -> InterposeC eff m a #

Monad m => Monad (InterposeC eff m) Source # 
Instance details

Defined in Control.Effect.Interpose

Methods

(>>=) :: InterposeC eff m a -> (a -> InterposeC eff m b) -> InterposeC eff m b #

(>>) :: InterposeC eff m a -> InterposeC eff m b -> InterposeC eff m b #

return :: a -> InterposeC eff m a #

fail :: String -> InterposeC eff m a #

Functor m => Functor (InterposeC eff m) Source # 
Instance details

Defined in Control.Effect.Interpose

Methods

fmap :: (a -> b) -> InterposeC eff m a -> InterposeC eff m b #

(<$) :: a -> InterposeC eff m b -> InterposeC eff m a #

Applicative m => Applicative (InterposeC eff m) Source # 
Instance details

Defined in Control.Effect.Interpose

Methods

pure :: a -> InterposeC eff m a #

(<*>) :: InterposeC eff m (a -> b) -> InterposeC eff m a -> InterposeC eff m b #

liftA2 :: (a -> b -> c) -> InterposeC eff m a -> InterposeC eff m b -> InterposeC eff m c #

(*>) :: InterposeC eff m a -> InterposeC eff m b -> InterposeC eff m b #

(<*) :: InterposeC eff m a -> InterposeC eff m b -> InterposeC eff m a #

runInterpose :: (forall x. eff m (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