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

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Writer

Synopsis

Documentation

data Writer w m k Source #

Constructors

Tell w k 
Listen (m a) (w -> a -> k) 
Censor (w -> w) (m a) (a -> k) 
Instances
Effect (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

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

HFunctor (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

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

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

Functor (Writer w m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

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

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

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

Defined in Control.Effect.Writer

Methods

ret :: a -> WriterC w m a Source #

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

tell :: (Member (Writer w) sig, Carrier sig m) => w -> m () Source #

Write a value to the log.

fst (run (runWriter (mapM_ (tell . Sum) (0 : ws)))) == foldMap Sum ws

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

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

run (runWriter (fst <$ tell (Sum a) <*> listen @(Sum Integer) (tell (Sum b)))) == (Sum a <> Sum b, Sum b)

listens :: (Member (Writer w) sig, Carrier 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.

run (runWriter (fst <$ tell (Sum a) <*> listens @(Sum Integer) (applyFun f) (tell (Sum b)))) == (Sum a <> Sum b, applyFun f (Sum b))

censor :: (Member (Writer w) sig, Carrier sig m) => (w -> w) -> m a -> m a Source #

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

run (execWriter (censor (applyFun f) (tell (Sum a)))) == applyFun f (Sum a)
run (execWriter (tell (Sum a) *> censor (applyFun f) (tell (Sum b)) *> tell (Sum c))) == (Sum a <> applyFun f (Sum b) <> Sum c)

runWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m (w, a) Source #

Run a Writer effect with a Monoidal log, producing the final log alongside the result value.

run (runWriter (tell (Sum a) *> pure b)) == (Sum a, b)

execWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m w Source #

Run a Writer effect with a Monoidal log, producing the final log and discarding the result value.

run (execWriter (tell (Sum a) *> pure b)) == Sum a

newtype WriterC w m a Source #

A space-efficient carrier for Writer effects.

This is based on a post Gabriel Gonzalez made to the Haskell mailing list: https://mail.haskell.org/pipermail/libraries/2013-March/019528.html

Note that currently, the constant-space behaviour observed there only occurs when using WriterC and VoidC without Eff wrapping them. See the benchmark component for details.

Constructors

WriterC 

Fields

Instances
(Monad m, Monoid w) => Monad (WriterC w m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

(>>=) :: WriterC w m a -> (a -> WriterC w m b) -> WriterC w m b #

(>>) :: WriterC w m a -> WriterC w m b -> WriterC w m b #

return :: a -> WriterC w m a #

fail :: String -> WriterC w m a #

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

Defined in Control.Effect.Writer

Methods

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

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

(Monad m, Monoid w) => Applicative (WriterC w m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

pure :: a -> WriterC w m a #

(<*>) :: WriterC w m (a -> b) -> WriterC w m a -> WriterC w m b #

liftA2 :: (a -> b -> c) -> WriterC w m a -> WriterC w m b -> WriterC w m c #

(*>) :: WriterC w m a -> WriterC w m b -> WriterC w m b #

(<*) :: WriterC w m a -> WriterC w m b -> WriterC w m a #

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

Defined in Control.Effect.Writer

Methods

ret :: a -> WriterC w m a Source #

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