HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepolysemy-1.9.2.0Haskell2010

Polysemy.Writer

  • 1 type
  • 13 values
  • Packagepolysemy-1.9.2.0
  • Exports14
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceWriter.hs

Effect

1 declaration
datadata Writer o (m :: Type -> Type) a where
#

An effect capable of emitting and intercepting messages.

Constructors

  • Tell :: o -> Writer o m ()

    Write a message to the log.

  • Listen :: m a1 -> Writer o m (o, a1)

    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

4 declarations
valuepass :: Member (Writer o) r => Sem r (o -> o, a) -> Sem r a
#

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

Interpretations

8 declarations
valuerunWriterAssocR :: Monoid o => Sem (Writer o ': r) a -> Sem r (o, a)
#

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.

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

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.

valuewriterToIOFinal
  1. :: (Monoid o, Member (Final IO) r)
  2. => Sem (Writer o ': r) a
  3. -> Sem r (o, a)
#

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.

valuewriterToIOAssocRFinal
  1. :: (Monoid o, Member (Final IO) r)
  2. => Sem (Writer o ': r) a
  3. -> Sem r (o, a)
#

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.

Interpretations for Other Effects

1 declaration