HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulecomonad-5.0.10Haskell2010

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
Contents
  1. The strict environment comonad
  2. The strict environment comonad transformer
  3. Combinators
Synopsis
  • Packagecomonad-5.0.10
  • Exports9
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceEnv.hs

The strict environment comonad

valueenv :: e -> a -> Env e a

Create an Env using an environment and a value

The strict environment comonad transformer

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

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.