fused-effects-0.3.1.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) => Carrier (Writer w :+: sig) (WriterC w m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

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

ret :: 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 :: Monoid w => 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 :: (Monoid w, Functor m) => 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

Constructors

WriterC 

Fields

Instances
MonadTrans (WriterC w) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

lift :: Monad m => m a -> WriterC w m a #

Monad m => 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 #

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

Defined in Control.Effect.Writer

Methods

fail :: String -> WriterC w m a #

Monad m => 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 #

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

Defined in Control.Effect.Writer

Methods

liftIO :: IO a -> WriterC w m a #

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

Defined in Control.Effect.Writer

Methods

empty :: WriterC w m a #

(<|>) :: WriterC w m a -> WriterC w m a -> WriterC w m a #

some :: WriterC w m a -> WriterC w m [a] #

many :: WriterC w m a -> WriterC w m [a] #

(Alternative m, Monad m) => MonadPlus (WriterC w m) Source # 
Instance details

Defined in Control.Effect.Writer

Methods

mzero :: WriterC w m a #

mplus :: WriterC w m a -> WriterC w m a -> WriterC w m a #

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

Defined in Control.Effect.Writer

Methods

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

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