fused-effects-1.0.2.0: A fast, flexible, fused effect system.
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Writer

Description

An effect allowing writes to an accumulated quantity alongside a computed value. A Writer w effect keeps track of a monoidal datum of type w and strictly appends to that monoidal value with the tell effect. Writes to that value can be detected and intercepted with the listen and censor effects.

Predefined carriers:

Since: 0.1.0.0

Synopsis

Writer effect

data Writer w m k Source #

Since: 0.1.0.0

Constructors

Tell w (m k) 
forall a. Listen (m a) (w -> a -> m k) 
forall a. Censor (w -> w) (m a) (a -> m k) 

Instances

Instances details
Effect (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Writer w m a -> Writer w n (ctx a) Source #

HFunctor (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer.Internal

Methods

hmap :: Functor m => (forall x. m x -> n x) -> Writer w m a -> Writer w n a Source #

Monoid w => Algebra (Writer w) ((,) w) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Writer w ((,) w) a -> (w, a) Source #

Functor m => Functor (Writer w m) Source # 
Instance details

Defined in Control.Effect.Writer.Internal

Methods

fmap :: (a -> b) -> Writer w m a -> Writer w m b #

(<$) :: a -> Writer w m b -> Writer w m a #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Monoid w, Algebra sig m, Effect sig) => Algebra (Writer w :+: sig) (WriterC w m) Source # 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

alg :: (Writer w :+: sig) (WriterC w m) a -> WriterC w m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

tell :: Has (Writer w) sig m => w -> m () Source #

Write a value to the log.

runWriter (tell w >> m) = first (mappend w) <$> runWriter m

Since: 0.1.0.0

listen :: Has (Writer w) sig m => m a -> m (w, a) Source #

Run a computation, returning the pair of its output and its result.

runWriter (listen m) = fmap (fst &&& id) (runWriter m)

Since: 0.2.0.0

listens :: Has (Writer w) sig m => (w -> b) -> m a -> m (b, a) Source #

Run a computation, applying a function to its output and returning the pair of the modified output and its result.

listens f m = fmap (first f) (listen m)

Since: 0.2.0.0

censor :: Has (Writer w) sig m => (w -> w) -> m a -> m a Source #

Run a computation, modifying its output with the passed function.

runWriter (censor f m) = fmap (first f) (runWriter m)

Since: 0.2.0.0

Re-exports

class (HFunctor sig, Monad m) => Algebra sig m | m -> sig Source #

The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg method.

Since: 1.0.0.0

Minimal complete definition

alg

Instances

Instances details
Algebra Choose NonEmpty Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Choose NonEmpty a -> NonEmpty a Source #

Algebra Empty Maybe Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Empty Maybe a -> Maybe a Source #

Algebra NonDet [] Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: NonDet [] a -> [a] Source #

Algebra sig m => Algebra sig (Alt m) Source #

This instance permits effectful actions to be lifted into the Alt monad, which eases the invocation of repeated alternation with <|>:

a <|> b <|> c <|> d

is equivalent to

getAlt (mconcat [a, b, c, d])

Since: 1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: sig (Alt m) a -> Alt m a Source #

Algebra sig m => Algebra sig (Ap m) Source #

This instance permits effectful actions to be lifted into the Ap monad given a monoidal return type, which can provide clarity when chaining calls to mappend.

mappend <$> act1 <*> (mappend <$> act2 <*> act3)

is equivalent to

getAp (act1 <> act2 <> act3)

Since: 1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: sig (Ap m) a -> Ap m a Source #

Algebra sig m => Algebra sig (IdentityT m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: sig (IdentityT m) a -> IdentityT m a Source #

Algebra (Lift IO) IO Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Lift IO IO a -> IO a Source #

Algebra (Lift Identity) Identity Source # 
Instance details

Defined in Control.Algebra

Monad m => Algebra (Lift m) (LiftC m) Source # 
Instance details

Defined in Control.Carrier.Lift

Methods

alg :: Lift m (LiftC m) a -> LiftC m a Source #

Algebra (Error e) (Either e) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Error e (Either e) a -> Either e a Source #

Monoid w => Algebra (Writer w) ((,) w) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Writer w ((,) w) a -> (w, a) Source #

Algebra (Reader r) ((->) r :: Type -> Type) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Reader r ((->) r) a -> r -> a Source #

(Algebra sig m, Effect sig) => Algebra (Choose :+: sig) (ChooseC m) Source # 
Instance details

Defined in Control.Carrier.Choose.Church

Methods

alg :: (Choose :+: sig) (ChooseC m) a -> ChooseC m a Source #

(Algebra sig m, Effect sig) => Algebra (Empty :+: sig) (EmptyC m) Source # 
Instance details

Defined in Control.Carrier.Empty.Maybe

Methods

alg :: (Empty :+: sig) (EmptyC m) a -> EmptyC m a Source #

(Algebra sig m, Effect sig) => Algebra (NonDet :+: sig) (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

alg :: (NonDet :+: sig) (NonDetC m) a -> NonDetC m a Source #

(MonadIO m, Algebra sig m) => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Printing

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

Algebra sig m => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Ignoring

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

(Algebra sig m, Effect sig) => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Returning

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

(Algebra sig m, Effect sig) => Algebra (Fail :+: sig) (FailC m) Source # 
Instance details

Defined in Control.Carrier.Fail.Either

Methods

alg :: (Fail :+: sig) (FailC m) a -> FailC m a Source #

(Algebra sig m, Effect sig) => Algebra (Fresh :+: sig) (FreshC m) Source # 
Instance details

Defined in Control.Carrier.Fresh.Strict

Methods

alg :: (Fresh :+: sig) (FreshC m) a -> FreshC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

alg :: (Cut :+: (NonDet :+: sig)) (CutC m) a -> CutC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

alg :: (Cull :+: (NonDet :+: sig)) (CullC m) a -> CullC m a Source #

Algebra sig m => Algebra (Reader r :+: sig) (ReaderT r m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: sig) (ReaderT r m) a -> ReaderT r m a Source #

Algebra sig m => Algebra (Reader r :+: sig) (ReaderC r m) Source # 
Instance details

Defined in Control.Carrier.Reader

Methods

alg :: (Reader r :+: sig) (ReaderC r m) a -> ReaderC r m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Strict

Methods

alg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Lazy

Methods

alg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source #

(Algebra sig m, Effect sig) => Algebra (Throw e :+: sig) (ThrowC e m) Source # 
Instance details

Defined in Control.Carrier.Throw.Either

Methods

alg :: (Throw e :+: sig) (ThrowC e m) a -> ThrowC e m a Source #

(Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (ExceptT e m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Error e :+: sig) (ExceptT e m) a -> ExceptT e m a Source #

(Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (ErrorC e m) Source # 
Instance details

Defined in Control.Carrier.Error.Either

Methods

alg :: (Error e :+: sig) (ErrorC e m) a -> ErrorC e m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Monoid w, Algebra sig m, Effect sig) => Algebra (Writer w :+: sig) (WriterC w m) Source # 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

alg :: (Writer w :+: sig) (WriterC w m) a -> WriterC w m a Source #

(HFunctor eff, HFunctor sig, Reifies s (Handler eff m), Monad m, Algebra sig m) => Algebra (eff :+: sig) (InterpretC s eff m) Source # 
Instance details

Defined in Control.Carrier.Interpret

Methods

alg :: (eff :+: sig) (InterpretC s eff m) a -> InterpretC s eff m a Source #

(LabelledMember label sub sig, HFunctor sub, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: (sub :+: sig) (UnderLabel label sub m) a -> UnderLabel label sub m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

(Algebra (eff :+: sig) (sub m), HFunctor eff, HFunctor sig) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: (Labelled label eff :+: sig) (Labelled label sub m) a -> Labelled label sub m a Source #

class HFunctor sig => Effect sig Source #

The class of effect types, which must:

  1. Be functorial in their last two arguments, and
  2. Support threading effects in higher-order positions through using the carrier’s suspended context.

All first-order effects (those without existential occurrences of m) admit a default definition of thread provided a Generic1 instance is available for the effect.

Since: 1.0.0.0

Instances

Instances details
Effect Choose Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Choose m a -> Choose n (ctx a) Source #

Effect Empty Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Empty m a -> Empty n (ctx a) Source #

Effect Trace Source # 
Instance details

Defined in Control.Effect.Trace

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Trace m a -> Trace n (ctx a) Source #

Effect Fresh Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Fresh m a -> Fresh n (ctx a) Source #

Effect Cut Source # 
Instance details

Defined in Control.Effect.Cut

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Cut m a -> Cut n (ctx a) Source #

Effect Cull Source # 
Instance details

Defined in Control.Effect.Cull

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Cull m a -> Cull n (ctx a) Source #

Effect (Catch e) Source # 
Instance details

Defined in Control.Effect.Catch.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Catch e m a -> Catch e n (ctx a) Source #

Functor sig => Effect (Lift sig) Source # 
Instance details

Defined in Control.Effect.Lift.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Lift sig m a -> Lift sig n (ctx a) Source #

Effect (Reader r) Source # 
Instance details

Defined in Control.Effect.Reader.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Reader r m a -> Reader r n (ctx a) Source #

Effect (State s) Source # 
Instance details

Defined in Control.Effect.State.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> State s m a -> State s n (ctx a) Source #

Effect (Throw e) Source # 
Instance details

Defined in Control.Effect.Throw.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Throw e m a -> Throw e n (ctx a) Source #

Effect (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Writer w m a -> Writer w n (ctx a) Source #

(Effect f, Effect g) => Effect (f :+: g) Source # 
Instance details

Defined in Control.Effect.Sum

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> (f :+: g) m a -> (f :+: g) n (ctx a) Source #

Effect sub => Effect (Labelled label sub) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Labelled label sub m a -> Labelled label sub n (ctx a) Source #

type Has eff sig m = (Members eff sig, Algebra sig m) Source #

m is a carrier for sig containing eff.

Note that if eff is a sum, it will be decomposed into multiple Member constraints. While this technically allows one to combine multiple unrelated effects into a single Has constraint, doing so has two significant drawbacks:

  1. Due to a problem with recursive type families, this can lead to significantly slower compiles.
  2. It defeats ghc’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.

run :: Identity a -> a Source #

Run an action exhausted of effects to produce its final result value.

Since: 1.0.0.0