Control.Comonad.Trans.Store.Memo

comonad-transformers-2.0.2: Comonad transformers

Portability | portable
Stability | provisional
Maintainer | Edward Kmett <ekmett@gmail.com>

Control.Comonad.Trans.Store.Memo

Contents

- The Store comonad
- The Store comonad transformer
- Operations

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

- type Store s = StoreT s Identity
- store :: (s -> a) -> s -> Store s a
- runStore :: Store s a -> (s -> a, s)
- data StoreT s w a
- storeT :: Functor w => w (s -> a) -> s -> StoreT s w a
- runStoreT :: StoreT s w a -> (w (s -> a), s)
- lowerStoreT :: StoreT s w a -> w a
- pos :: StoreT s w a -> s
- seek :: Comonad w => s -> StoreT s w a -> StoreT s w a
- seeks :: Comonad w => (s -> s) -> StoreT s w a -> StoreT s w a
- peek :: Comonad w => s -> StoreT s w a -> a
- peeks :: Comonad w => (s -> s) -> StoreT s w a -> a

# The Store comonad

type Store s = StoreT s Identity

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

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

# The Store comonad transformer

data StoreT s w a

Instances

ComonadTrans (StoreT s) |
ComonadHoist (StoreT s) |
Functor w => Functor (StoreT s w) |
(Typeable s, Typeable1 w) => Typeable1 (StoreT s w) |
(Applicative w, Semigroup s, Monoid s) => Applicative (StoreT s w) |
Comonad w => Comonad (StoreT s w) |
Extend w => Extend (StoreT s w) |
(Apply w, Semigroup s) => Apply (StoreT s w) |
(Typeable s, Typeable1 w, Typeable a) => Typeable (StoreT s w a) |

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

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

lowerStoreT :: StoreT s w a -> w a

# Operations

pos :: StoreT s w a -> s

Read the current position

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

Seek to an absolute location

     seek s = peek s . duplicate

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

Seek to a relative location

     seeks f = peeks f . duplicate

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

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 -> a

Peek at a value at a given relative location