Community
Modules 15

Control.Comonad.Trans.Env

provisional

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

This module specifies the environment comonad transformer (aka coreader), which is left adjoint to the reader comonad.

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

The strict environment comonad

type Env e = EnvT e Identity

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

Create an Env using an environment and a value

The strict environment comonad transformer

data EnvT e w a

EnvT :: e -> (w a) -> EnvT e w a

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.

Instances

9
  • instance (Data e, Typeable w, Data (w a), Data a) => Data (EnvT e w a)
  • instance Functor w => Functor (EnvT e w)
  • instance Comonad w => Comonad (EnvT e w)
  • instance ComonadTrans (EnvT e)
  • instance (Monoid e, Applicative m) => Applicative (EnvT e m)
  • instance ComonadHoist (EnvT e)
  • instance (Semigroup e, ComonadApply w) => ComonadApply (EnvT e w)
  • instance Foldable w => Foldable (EnvT e w)
  • instance Traversable w => Traversable (EnvT e w)
Maintainer
Edward Kmett <ekmett@gmail.com>
Portability
portable
Copyright
(C) 2008-2013 Edward Kmett
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-aa6debbd-web-3

Metadata snapshot: 654821c0cfecd2668d9ddddd0bf4f45d1d796802db984d918e0d3e66c14a0555

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.