Modules 15
Control.Comonad.Trans.Env
provisionalThe 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 0Extract simply retrieves the value:
>>> extract initial
0Play around with the value, in our case producing a negative value:
>>> let experiment = fmap (+ 10) initial
>>> extract experiment
10Oh noes, something went wrong, 10 isn't very negative! Better restore the initial value using the default:
>>> let initialRestored = experiment =>> ask
>>> extract initialRestored
0The strict environment comonad
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
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 . asklocal :: (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
- aihc-base-4.21.2.0 · Core library · Cabal file
- aihc-internal-9.1204.0 · Core library · Cabal file
- aihc-prim-0.13.0 · Core library · Cabal file
- aihc-rts-1.0.2 · Core library · Cabal file
- aihc-template-haskell-2.23.0.0 · Core library · Cabal file
- array-0.5.8.0 · Cabal revision 2 · Cabal file · Source archive
- comonad-5.0.10 · Cabal revision 0 · Cabal file · Source archive
- containers-0.8.1 · Cabal revision 0 · Cabal file · Source archive
- deepseq-1.5.2.0 · Cabal revision 0 · Cabal file · Source archive
- distributive-0.6.3 · Cabal revision 0 · Cabal file · Source archive
- indexed-traversable-0.1.5 · Cabal revision 0 · Cabal file · Source archive
- tagged-0.9 · Cabal revision 0 · Cabal file · Source archive
- transformers-0.6.3.0 · Cabal revision 2 · Cabal file · Source archive