HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulecomonad-5.0.9Haskell2010

Control.Comonad.Trans.Env

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:

Example1 expression
let initial = env 0 0

Extract simply retrieves the value:

Example1 expression
extract initial0

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

Example2 expressions
let experiment = fmap (+ 10) initialextract experiment10

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

Example2 expressions
let initialRestored = experiment =>> askextract initialRestored0
  • 2 types
  • 7 values
  • Packagecomonad-5.0.9
  • Exports9
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceEnv.hs

The strict environment comonad

3 declarations
valueenv :: e -> a -> Env e a
#

Create an Env using an environment and a value

The strict environment comonad transformer

3 declarations
datadata EnvT e (w :: Type -> Type) a
#

Constructors

Instances12ComonadEnv, ComonadStore, ComonadTraced, ComonadTrans, ComonadHoist, Functor, …
valuelowerEnvT :: 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

3 declarations
valueask :: EnvT e w a -> e
#

Retrieves the environment.

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

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

asks = f . ask
valuelocal :: (e -> e') -> EnvT e w a -> EnvT e' w a
#

Modifies the environment using the specified function.