polysemy-1.9.0.0: Higher-order, low-boilerplate free monads.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Writer

Description

 
Synopsis

Effect

data Writer o m a where Source #

An effect capable of emitting and intercepting messages.

Constructors

Tell :: o -> Writer o m ()

Write a message to the log.

Listen :: forall o m a. m a -> Writer o m (o, a)

Return the log produced by the higher-order action.

Pass :: m (o -> o, a) -> Writer o m a

Run the given action and apply the function it returns to the log.

Actions

tell :: forall o r. Member (Writer o) r => o -> Sem r () Source #

Write a message to the log.

listen :: forall o r a. Member (Writer o) r => Sem r a -> Sem r (o, a) Source #

Return the log produced by the higher-order action.

pass :: forall o r a. Member (Writer o) r => Sem r (o -> o, a) -> Sem r a Source #

Run the given action and apply the function it returns to the log.

censor :: Member (Writer o) r => (o -> o) -> Sem r a -> Sem r a Source #

Since: 0.7.0.0

Interpretations

runWriter :: Monoid o => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Run a Writer effect in the style of WriterT (but without the nasty space leak!)

runLazyWriter :: forall o r a. Monoid o => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Run a Writer effect in the style of WriterT lazily.

Warning: This inherits the nasty space leak issue of WriterT! Don't use this if you don't have to.

Since: 1.3.0.0

runWriterAssocR :: Monoid o => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Like runWriter, but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of runWriter if the monoid is a list, such as String.

Since: 1.1.0.0

runLazyWriterAssocR :: Monoid o => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Like runLazyWriter, but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of runLazyWriter if the monoid is a list, such as String.

Warning: This inherits the nasty space leak issue of WriterT! Don't use this if you don't have to.

Since: 1.3.0.0

runWriterTVar :: (Monoid o, Member (Final IO) r) => TVar o -> Sem (Writer o ': r) a -> Sem r a Source #

Transform a Writer effect into atomic operations over a TVar through final IO.

Since: 1.2.0.0

writerToIOFinal :: (Monoid o, Member (Final IO) r) => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Run a Writer effect by transforming it into atomic operations through final IO.

Internally, this simply creates a new TVar, passes it to runWriterTVar, and then returns the result and the final value of the TVar.

Beware: Effects that aren't interpreted in terms of IO will have local state semantics in regards to Writer effects interpreted this way. See Final.

Since: 1.2.0.0

writerToIOAssocRFinal :: (Monoid o, Member (Final IO) r) => Sem (Writer o ': r) a -> Sem r (o, a) Source #

Like writerToIOFinal. but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of writerToIOFinal if the monoid is a list, such as String.

Beware: Effects that aren't interpreted in terms of IO will have local state semantics in regards to Writer effects interpreted this way. See Final.

Since: 1.2.0.0

writerToEndoWriter :: (Monoid o, Member (Writer (Endo o)) r) => Sem (Writer o ': r) a -> Sem r a Source #

Transform a Writer o effect into a Writer (Endo o) effect, right-associating all uses of <> for o.

This can be used together with raiseUnder in order to create -AssocR variants out of regular Writer interpreters.

Since: 1.2.0.0

Interpretations for Other Effects

outputToWriter :: Member (Writer o) r => Sem (Output o ': r) a -> Sem r a Source #

Transform an Output effect into a Writer effect.

Since: 1.0.0.0