Copyright | (C) 2008-2013 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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
The strict environment comonad transformer
EnvT e (w a) |
Comonad w => ComonadEnv e (EnvT e w) # | |
ComonadStore s w => ComonadStore s (EnvT e w) # | |
ComonadTraced m w => ComonadTraced m (EnvT e w) # | |
ComonadHoist (EnvT e) # | |
ComonadTrans (EnvT e) # | |
Functor w => Functor (EnvT e w) # | |
(Monoid e, Applicative m) => Applicative (EnvT e m) # | |
Foldable w => Foldable (EnvT e w) # | |
Traversable w => Traversable (EnvT e w) # | |
(Semigroup e, ComonadApply w) => ComonadApply (EnvT e w) # | |
Comonad w => Comonad (EnvT e w) # | |
(Data e, Typeable (* -> *) w, Data (w a), Data a) => Data (EnvT 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.