comonad-extras- Comonad transformers requiring extensions to Haskell 98

MaintainerEdward Kmett <>




The array-backed 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)

Thanks go to Russell O'Connor and Daniel Peebles for their help formulating and proving the laws for this comonad transformer.

This basic version of this transformer first appeared on Dan Piponi's blog at

Since this module relies on the non-Haskell 98 arrays package, it is located here instead of in comonad-transformers.

NB: attempting to seek or peek out of bounds will yield an error.


The Pointer comonad

pointer :: Array i a -> i -> Pointer i aSource

runPointer :: Pointer i a -> (Array i a, i)Source

The Pointer comonad transformer

data PointerT i w a Source


PointerT (w (Array i a)) i 


(ComonadEnv m w, Ix i) => ComonadEnv m (PointerT i w) 
(Comonad w, Ix i) => ComonadStore i (PointerT i w) 
(ComonadTraced m w, Ix i) => ComonadTraced m (PointerT i w) 
Ix i => ComonadHoist (PointerT i) 
Ix i => ComonadTrans (PointerT i) 
(Functor w, Ix i) => Functor (PointerT i w) 
(Typeable i, Typeable1 w) => Typeable1 (PointerT i w) 
(Comonad w, Ix i) => Comonad (PointerT i w) 
(Comonad w, Ix i) => Extend (PointerT i w) 
(Typeable i, Typeable1 w, Typeable a) => Typeable (PointerT i w a) 

runPointerT :: PointerT i w a -> (w (Array i a), i)Source

pointerBounds :: (Comonad w, Ix i) => PointerT i w a -> (i, i)Source

Extract the bounds of the currently focused array