comonad-transformers-2.0.3: Comonad transformers

Portabilityportable
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Infered

Control.Comonad.Trans.Store.Memo

Contents

Description

The memoizing store (state-in-context/costate) comonad transformer is subject to the laws:

 x = seek (pos x) x
 y = pos (seek y x)
 seek y x = seek y (seek z x)

This version of the transformer lazily memoizes the result of applying the comonad to the current state. This can be useful for avoiding redundant computation if you reuse the same StoreT object multiple times.

Synopsis

The Store comonad

store :: (s -> a) -> s -> Store s aSource

runStore :: Store s a -> (s -> a, s)Source

The Store comonad transformer

data StoreT s w a Source

Instances

storeT :: Functor w => w (s -> a) -> s -> StoreT s w aSource

runStoreT :: StoreT s w a -> (w (s -> a), s)Source

lowerStoreT :: StoreT s w a -> w aSource

Operations

pos :: StoreT s w a -> sSource

Read the current position

seek :: Comonad w => s -> StoreT s w a -> StoreT s w aSource

Seek to an absolute location

 seek s = peek s . duplicate

seeks :: Comonad w => (s -> s) -> StoreT s w a -> StoreT s w aSource

Seek to a relative location

 seeks f = peeks f . duplicate

peek :: Comonad w => s -> StoreT s w a -> aSource

Peek at a value at a given absolute location

 peek x . extend (peek y) = peek y

peeks :: Comonad w => (s -> s) -> StoreT s w a -> aSource

Peek at a value at a given relative location