category-extras-0.2: Various modules and constructs inspired by category theory.Source codeContentsIndex
Control.Comonad.Context
Portabilityportable
Stabilityexperimental
Maintainerdan.doel@gmail.com
Description
Defines the state-in-context comonad, which is dual to the state monad. Each operation in the context comonad runs in a context determined by later operations. (Observe, for example, experiment, which runs the preceeding operations multiple times in different contexts and returns a list of results.)
Synopsis
data Context c a = Context (c -> a) c
get :: Context c a -> c
modify :: (c -> c) -> Context c a -> a
experiment :: [c -> c] -> Context c a -> [a]
liftCtx :: (a -> b) -> Context c a -> b
Documentation
data Context c a Source
Constructors
Context (c -> a) c
show/hide Instances
get :: Context c a -> cSource
Returns the context
modify :: (c -> c) -> Context c a -> aSource
Returns the result of the preceeding operations running in a modified context
experiment :: [c -> c] -> Context c a -> [a]Source
Returns a list of results created by running prior operations in modified contexts created by the list of context-modifiers.
liftCtx :: (a -> b) -> Context c a -> bSource

Lifts an operation into the context comonad. Syntactic sugar for fmap when chaining comonad operations.

  liftCtx         == extract . fmap f
  w =>> liftCtx f == fmap f w
Produced by Haddock version 2.3.0