1

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!

Chris Penner
  • 1,881
  • 11
  • 15
  • Could `fmap` be the function that you're looking for? – Mark Seemann Mar 31 '18 at 08:31
  • @MarkSeemann `fmap` isn't quite right, because it alters every value in the functor. The questioneer is looking to alter only the one at the comonad's focus, zipper-style. – Benjamin Hodgson Mar 31 '18 at 10:24
  • I'm fairly sure I've addressed this in [my answer](https://stackoverflow.com/questions/49585295/lenses-over-comonads-or-representable/49586925#49586925) to [your other question](https://stackoverflow.com/questions/49585295/lenses-over-comonads-or-representable), so I'm going to close this one as a dupe. Please let me know if you think I'm wrong about that though. – Benjamin Hodgson Mar 31 '18 at 11:02

0 Answers0