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)
Maintainerymdfield@outlook.jp
Safe HaskellNone
LanguageGHC2021

Data.Effect.Reader

Description

Effects that can be used to hold environmental values in the context. Environmental values are immutable and do not change across procedures, but you can modify the value within a local scope using the local operation.

Synopsis

Documentation

data Ask r a where Source #

An effect that holds a value of type r in the context (environment).

Constructors

Ask :: forall r. Ask r r

Obtain a value from the environment.

data Local r (f :: Type -> Type) a where Source #

An effect that locally modifies the value held in the environment.

Constructors

Local

Locally modifies the value held in the environment.

Fields

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

    A function that transforms the original value to the modified value.

  • -> f a

    The local scope where the modification is applied.

  • -> Local r f a
     

Instances

Instances details
() => HFunctor (Local r) Source # 
Instance details

Defined in Data.Effect.Reader

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> Local r f :-> Local r g #

type LAsk r = LiftFOE (Ask r) Source #

pattern LAsk :: forall a r f. () => (a ~ r, ()) => LiftFOE (Ask r) f a Source #

ask :: SendFOE (Ask r) f => f r Source #

Obtain a value from the environment.

ask' :: forall {k} (tag :: k) r f. SendFOE (Tag (Ask r) tag) f => f r Source #

Obtain a value from the environment.

ask'' :: forall {k} (key :: k) r f. SendFOEBy key (Ask r) f => f r Source #

Obtain a value from the environment.

local Source #

Arguments

:: forall r a f. SendHOE (Local r) f 
=> (r -> r) 
-> f a

The local scope where the modification is applied.

-> f a 

Locally modifies the value held in the environment.

local' Source #

Arguments

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

The local scope where the modification is applied.

-> f a 

Locally modifies the value held in the environment.

local'' Source #

Arguments

:: forall {k} (key :: k) r a f. SendHOEBy key (Local r) f 
=> (r -> r) 
-> f a

The local scope where the modification is applied.

-> f a 

Locally modifies the value held in the environment.

asks :: (Ask r <: f, Functor f) => (r -> a) -> f a Source #

Obtains a value from the environment and returns it transformed by the given function.