category-extras-0.1: Various modules and constructs inspired by category theory.Source codeContentsIndex
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.)
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
data Context c a Source
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