data-effects-0.4.2.0: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2023-2025 Sayo contributors
LicenseMPL-2.0 (see the file LICENSE)
Maintainerymdfield@outlook.jp
Safe HaskellNone
LanguageGHC2021

Data.Effect.Writer

Description

Effects that can accumulate values monoidally in a context.

Synopsis

Documentation

tell :: forall w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tell w :> es) => w -> a () Source #

listen :: forall a1 w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, WriterH w :> es) => a a1 -> a (w, a1) Source #

censor :: forall w b a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, WriterH w :> es) => (w -> w) -> a b -> a b Source #

censorPre :: forall w (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) a (c :: (Type -> Type) -> Constraint). (In (Tell w) es, Free c ff) => (w -> w) -> Eff ff es a -> Eff ff es a Source #

censor with pre-applying semantics.

tell'_ :: forall w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, In (Tell w) es) => w -> a () Source #

tell' :: forall {k} (key :: k) w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Has key (Tell w) es) => w -> a () Source #

tell'' :: forall {k} (tag :: k) w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tagged tag (Tell w) :> es) => w -> a () Source #

listen' :: forall {k} (key :: k) a1 w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Has key (WriterH w) es) => a a1 -> a (w, a1) Source #

listen'' :: forall {k} (tag :: k) a1 w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tagged tag (WriterH w) :> es) => a a1 -> a (w, a1) Source #

listen'_ :: forall a1 w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, In (WriterH w) es) => a a1 -> a (w, a1) Source #

censor' :: forall {k} (key :: k) w b a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Has key (WriterH w) es) => (w -> w) -> a b -> a b Source #

censor'' :: forall {k} (tag :: k) w b a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, Tagged tag (WriterH w) :> es) => (w -> w) -> a b -> a b Source #

censor'_ :: forall w b a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, a ~ Eff ff es, In (WriterH w) es) => (w -> w) -> a b -> a b Source #

data Tell w (a :: Type -> Type) b where #

An effect that can accumulate values monoidally in a context.

Constructors

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

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

Instances

Instances details
FirstOrder (Tell w) 
Instance details

Defined in Data.Effect

PolyHFunctor (Tell w) 
Instance details

Defined in Data.Effect

HFunctor (Tell w) 
Instance details

Defined in Data.Effect

Methods

hfmap :: (forall x. f x -> g x) -> Tell w f a -> Tell w g a #

type FormOf (Tell w) 
Instance details

Defined in Data.Effect

type FormOf (Tell w) = 'Polynomial
type LabelOf (Tell w) 
Instance details

Defined in Data.Effect

type OrderOf (Tell w) 
Instance details

Defined in Data.Effect

type OrderOf (Tell w) = 'FirstOrder

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

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 (a :: Type -> Type) a1 w. a a1

    The scope from which to obtain the accumulation.

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

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

Fields

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

    A function for modifying the accumulated value.

  • -> a b

    The scope where the modification is applied.

  • -> WriterH w a b
     

Instances

Instances details
PolyHFunctor (WriterH w) 
Instance details

Defined in Data.Effect

HFunctor (WriterH w) 
Instance details

Defined in Data.Effect

Methods

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

type FormOf (WriterH w) 
Instance details

Defined in Data.Effect

type LabelOf (WriterH w) 
Instance details

Defined in Data.Effect

type OrderOf (WriterH w) 
Instance details

Defined in Data.Effect

pass :: forall w a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Tell w :> es, WriterH w :> es, Monad (Eff ff es), Free c ff) => Eff ff es (w -> w, a) -> Eff ff es a #

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