HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulefused-effects-1.1.2.7Haskell2010

Control.Effect.Writer

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:

  • 2 types
  • 1 class
  • 5 values

Writer effect

5 declarations
datadata Writer w (m :: Type -> Type) k where
#

Constructors

Instances9Algebra, …
valuelisten :: Has (Writer w) sig m => m a -> m (w, a)
#

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

runWriter (listen m) = fmap (fst &&& id) (runWriter m)
valuelistens :: Has (Writer w) sig m => (w -> b) -> m a -> m (b, a)
#

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)
valuecensor :: Has (Writer w) sig m => (w -> w) -> m a -> m a
#

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

runWriter (censor f m) = fmap (first f) (runWriter m)

Re-exports

3 declarations
classclass Monad m => Algebra (sig :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) | m -> sig where
#

The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg method.

Instances53Algebra, …
typetype Has (eff :: (Type -> Type) -> Type -> Type) (sig :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Members eff sig, Algebra sig m)
#

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.

valuerun :: Identity a -> a
#

Run an action exhausted of effects to produce its final result value.