I'm using Control.Comonad.Representable.Store to represent a grid object for a game; the grid is: type Grid = Store (Compose Vector Vector) a
; where Vector has a representable instance indexed by Int
.
This allows me to use comonadic extend
and experiment
for grid squares to interact with their neighbours, and for me to use the focus of the Store monad (indicated by pos
) as a cursor into the grid.
What I'm looking for is a reasonable way to set the value at the focus of the store, or to use the Representable
instance of Compose Vector Vector
to set/mutate values at a given index. So far as I can tell, using the tools in Comonad
and Representable
I can only get values out of the structure, I can't find any function like: over :: ComonadStore s w => (a -> a) -> w a -> w a
or even Representable f => set :: f a -> Rep f -> a -> f a
.
Sure, I can index into the vectors, adjust the value, then set it back at its index; or even use tabulate
to rebuild the structure but with the adjustments made, but those sound inefficient and inelegent. It seems like some combination of these typeclasses would be able to do this for me; or if there's some other constraint/typeclass that I'm missing which could help out here.
Thanks!