HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulefused-effects-1.1.2.7Haskell2010

Control.Effect.Accum

An effect allowing writes to an accumulated quantity alongside a computed value, and reads from the accumulator. An Accum w effect keeps track of a monoidal datum of type w and strictly appends to that monoidal value with the add effect. Previous writes to that value can be read with the look effect.

Predefined carriers:

If Accum w is the last effect in a stack, it can be interpreted to a function w -> (w, a) given some result type a and the presence of a Monoid instance for w.

  • - | @since 1.1.2.0

Contents
  1. Accumulation effect
  2. Re-exports
Synopsis

Accumulation effect

datadata Accum w (m :: Type -> Type) k where

Constructors

Instances4Algebra
valuelook :: Has (Accum w) sig m => m w

Look up the previous accumulation

runAccum w look = return (w, w)
runAccum w (look >>= continuation) = runAccum w (continuation w)
valuelooks :: Has (Accum w) sig m => (w -> a) -> m a

Look up the previous accumulation and apply a function to it.

looks f = fmap f look

Re-exports

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.