I am strugling with the following problem. I am trying to make Game of Life using store comonads in Haskell. I have the following relevant code:
type Cel = ((Float, Float), Bool)
type Field2D = [[Cel]]
I have then created an initial field:
initialField2D = [[((0.0, 0.0), True), ((0.0, 1.0), True)],
[((1.0, 0.0), True), ((1.0, 1.0), True)]]
The initial field is a small example where I want to test my program on. Now here comes the tricky part.
initialStore2D :: Store Field Cel
initialStore2D = Store (head.head) initialField2D
f :: (Store Field2D Cel) -> Cel
f (Store f s) = cellUpdate (f s)
cellUpdate :: Cel -> Cel --Simple trivial cell update function that just moves one spot.
cellUpdate ((x, y), a) = ((x+1, y+1), True)
newStore = extend f initialStore2D -- Apply the update function to every cell.
extract newStore --Correctly returns ((1.0, 1.0), True)
Now my question is, what is a good way to change the focus onto the updated store? Moving down is simple:
goDown :: Store Field Cel
goDown (Store f s) = Store (f.tail) s
My question is, what would be a good way to move right or left for example? Did I chose a bad index function (head.head)?
Thank you for your time!