data-effects-0.3.0.1: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2023 Sayo Koyoneda
LicenseMPL-2.0 (see the file LICENSE)
Maintainer[email protected]
Safe HaskellNone
LanguageGHC2021

Data.Effect.Writer

Description

Effects that can accumulate values monoidally in a context.

Synopsis

Documentation

data Tell w a where Source #

An effect that can accumulate values monoidally in a context.

Constructors

Tell :: forall w. w -> Tell w ()

Accumulates new values to the cumulative value held in the context.

data WriterH w (f :: Type -> Type) a where Source #

An effect that performs local operations on accumulations in the context on a per-scope basis.

Constructors

Listen

Obtains the accumulated value in the scope and returns it together as a pair.

Fields

  • :: forall (f :: Type -> Type) a1 w. f a1

    The scope from which to obtain the accumulation.

  • -> WriterH w f (w, a1)
     
Censor

Modifies the accumulation in the scope based on the given function.

Fields

  • :: forall w (f :: Type -> Type) a. (w -> w)

    A function for modifying the accumulated value.

  • -> f a

    The scope where the modification is applied.

  • -> WriterH w f a
     

Instances

Instances details
() => HFunctor (WriterH w) Source # 
Instance details

Defined in Data.Effect.Writer

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> WriterH w f :-> WriterH w g #

type LTell w = LiftFOE (Tell w) Source #

pattern LTell :: forall a w f. () => (a ~ (), ()) => w -> LiftFOE (Tell w) f a Source #

tell :: SendFOE (Tell w) f => w -> f () Source #

Accumulates new values to the cumulative value held in the context.

tell' :: forall {k} (tag :: k) w f. SendFOE (Tag (Tell w) tag) f => w -> f () Source #

Accumulates new values to the cumulative value held in the context.

tell'' :: forall {k} (key :: k) w f. SendFOEBy key (Tell w) f => w -> f () Source #

Accumulates new values to the cumulative value held in the context.

listen Source #

Arguments

:: forall a w f. SendHOE (WriterH w) f 
=> f a

The scope from which to obtain the accumulation.

-> f (w, a) 

Obtains the accumulated value in the scope and returns it together as a pair.

listen' Source #

Arguments

:: forall {k} (tag :: k) a w f. SendHOE (TagH (WriterH w) tag) f 
=> f a

The scope from which to obtain the accumulation.

-> f (w, a) 

Obtains the accumulated value in the scope and returns it together as a pair.

listen'' Source #

Arguments

:: forall {k} (key :: k) a w f. SendHOEBy key (WriterH w) f 
=> f a

The scope from which to obtain the accumulation.

-> f (w, a) 

Obtains the accumulated value in the scope and returns it together as a pair.

censor Source #

Arguments

:: forall w a f. SendHOE (WriterH w) f 
=> (w -> w) 
-> f a

The scope where the modification is applied.

-> f a 

Modifies the accumulation in the scope based on the given function.

censor' Source #

Arguments

:: forall {k} (tag :: k) w a f. SendHOE (TagH (WriterH w) tag) f 
=> (w -> w) 
-> f a

The scope where the modification is applied.

-> f a 

Modifies the accumulation in the scope based on the given function.

censor'' Source #

Arguments

:: forall {k} (key :: k) w a f. SendHOEBy key (WriterH w) f 
=> (w -> w) 
-> f a

The scope where the modification is applied.

-> f a 

Modifies the accumulation in the scope based on the given function.

pass :: (Tell w <: m, WriterH w <<: m, Monad m) => m (w -> w, a) -> m a Source #

For a given scope, uses the function (the first component of the pair returned by that scope) to modify the accumulated value of that scope, and then accumulates the result into the current outer scope.

pass m = do
    (w, (f, a)) <- listen m
    tell $ f w
    pure a