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

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Writer

Contents

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) 
Listen (m a) (w -> a -> m k) 
Censor (w -> w) (m a) (a -> m k) 
Instances
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
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 (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 #

(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 #

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