Control.Reader
The canonical Reader(r) effect: a read-only ambient environment.
ask pulls a value from a context the code never threads through its own signature; run_reader supplies it, so one function runs against any environment. local runs a sub-computation under a transformed environment. Opt-in: not in Base.
Effects
Reader
effect Reader(r)
ask() : r
Read the ambient environment of type r.
Functions and Values
run_reader
run_reader : forall e0 a b. (a, () -> b ! {Control.Reader.Reader(a), e0}) -> b ! {e0}
Run action with env as the ambient environment, discharging Reader(r).
run_reader("hello", \() -> asks(str_len))
5
asks
asks : forall a b. ((a) -> b) -> b ! {Control.Reader.Reader(a)}
Read a projection f of the environment.
local
local : forall e0 a b. ((a) -> a, () -> b ! {Control.Reader.Reader(a), Control.Reader.Reader(a), e0}) -> b ! {Control.Reader.Reader(a), e0}
Run action under the environment transformed by f. The transformed environment is scoped to action; the outer environment is unchanged.
run_reader(10, \() -> [ask(), local(\(n) -> n + 5, \() -> ask()), ask()])
[10, 15, 10]