Description

The environment comonad holds a value along with some retrievable context.

The following sets up an experiment that retains its initial value in the background:

>>> let initial = env 0 0


Extract simply retrieves the value:

>>> extract initial
0


Play around with the value, in our case producing a negative value:

>>> let experiment = fmap (+ 10) initial
>>> extract experiment
10


Oh noes, something went wrong, 10 isn't very negative! Better restore the initial value using the default:

>>> let initialRestored = experiment =>> ask
>>> extract initialRestored
0


Synopsis

type Env e = EnvT e Identity #

env :: e -> a -> Env e a #

Create an Env using an environment and a value

runEnv :: Env e a -> (e, a) #

# The strict environment comonad transformer

data EnvT e w a #

Constructors

 EnvT e (w a)

Instances

runEnvT :: EnvT e w a -> (e, w a) #

lowerEnvT :: EnvT e w a -> w a #

Gets rid of the environment. This differs from extract in that it will not continue extracting the value from the contained comonad.

# Combinators

ask :: EnvT e w a -> e #

Retrieves the environment.

asks :: (e -> f) -> EnvT e w a -> f #

Like ask, but modifies the resulting value with a function.

asks = f . ask

local :: (e -> e') -> EnvT e w a -> EnvT e' w a #

Modifies the environment using the specified function.