polysemy-0.2.0.0: Higher-order, low-boilerplate, zero-cost free monads.

Polysemy.Internal.Combinators

Synopsis

# First order

Arguments

 :: FirstOrder m0 e "interpret" => (forall x m. e m x -> Sem r x) A natural transformation from the handled effect to other effects already in Sem. -> Sem (e ': r) a -> Sem r a

The simplest way to produce an effect handler. Interprets an effect e by transforming it into other effects inside of r.

Arguments

 :: (Member e r, FirstOrder m0 e "intercept") => (forall x m. e m x -> Sem r x) A natural transformation from the handled effect to other effects already in Sem. -> Sem r a Unlike interpret, intercept does not consume any effects. -> Sem r a

Like interpret, but instead of handling the effect, allows responding to the effect while leaving it unhandled. This allows you, for example, to intercept other effects and insert logic around them.

Arguments

 :: FirstOrder m0 e1 "reinterpret" => (forall m x. e1 m x -> Sem (e2 ': r) x) A natural transformation from the handled effect to the new effect. -> Sem (e1 ': r) a -> Sem (e2 ': r) a

Like interpret, but instead of removing the effect e, reencodes it in some new effect f. This function will fuse when followed by runState, meaning it's free to reinterpret in terms of the State effect and immediately run it.

Arguments

 :: FirstOrder m0 e1 "reinterpret2" => (forall m x. e1 m x -> Sem (e2 ': (e3 ': r)) x) A natural transformation from the handled effect to the new effects. -> Sem (e1 ': r) a -> Sem (e2 ': (e3 ': r)) a

Like reinterpret, but introduces two intermediary effects.

Arguments

 :: FirstOrder m0 e1 "reinterpret3" => (forall m x. e1 m x -> Sem (e2 ': (e3 ': (e4 ': r))) x) A natural transformation from the handled effect to the new effects. -> Sem (e1 ': r) a -> Sem (e2 ': (e3 ': (e4 ': r))) a

Like reinterpret, but introduces three intermediary effects.

# Higher order

Arguments

 :: (forall x m. e m x -> Tactical e m r x) A natural transformation from the handled effect to other effects already in Sem. -> Sem (e ': r) a -> Sem r a

Like interpret, but for higher-order effects (ie. those which make use of the m parameter.)

See the notes on Tactical for how to use this function.

Arguments

 :: Member e r => (forall x m. e m x -> Tactical e m r x) A natural transformation from the handled effect to other effects already in Sem. -> Sem r a Unlike interpretH, interceptH does not consume any effects. -> Sem r a

Like interceptH, but for higher-order effects.

See the notes on Tactical for how to use this function.

Arguments

 :: (forall m x. e1 m x -> Tactical e1 m (e2 ': r) x) A natural transformation from the handled effect to the new effect. -> Sem (e1 ': r) a -> Sem (e2 ': r) a

Like reinterpret, but for higher-order effects.

See the notes on Tactical for how to use this function.

Arguments

 :: (forall m x. e1 m x -> Tactical e1 m (e2 ': (e3 ': r)) x) A natural transformation from the handled effect to the new effects. -> Sem (e1 ': r) a -> Sem (e2 ': (e3 ': r)) a

Like reinterpret2, but for higher-order effects.

See the notes on Tactical for how to use this function.

Arguments

 :: (forall m x. e1 m x -> Tactical e1 m (e2 ': (e3 ': (e4 ': r))) x) A natural transformation from the handled effect to the new effects. -> Sem (e1 ': r) a -> Sem (e2 ': (e3 ': (e4 ': r))) a

Like reinterpret3, but for higher-order effects.

See the notes on Tactical for how to use this function.

# Statefulness

stateful :: (forall x m. e m x -> s -> Sem r (s, x)) -> s -> Sem (e ': r) a -> Sem r (s, a) Source #

Like interpret, but with access to an intermediate state s.

lazilyStateful :: (forall x m. e m x -> s -> Sem r (s, x)) -> s -> Sem (e ': r) a -> Sem r (s, a) Source #

Like interpret, but with access to an intermediate state s.