nhamblet / golf

Conway's Game of Life (Functional-y)
0 stars 0 forks source link

Evaluate using extract to get neighbor values #1

Open nhamblet opened 4 years ago

nhamblet commented 4 years ago

In the readme, I call out a question about using extract in the step where you evaluate a cell's neighbors values. Basically, in lifeStep(pg: PointedGrid[Boolean]): Boolean, should that method know how to access the PointedGrid internal grid, or since that's what the Comonad's extract does, should we rely on that instead?

In my initial version, I decided to use extract, but playing with both and understanding what they allow, and which chunk of code has which responsibilities would be fun.

nhamblet commented 4 years ago

@justinhj, who's video prompted me to write this up, kindly offered that "The purpose of the coflatMap is to let you look at the entire "enlarged" dataset at once", arguing somewhat for not worrying about using extract.

nhamblet commented 4 years ago

I've coded up another version where now one can implement the game for any comonad where there's a definition of neighbors. If the "step" functions had known how to access grid coordinates, changing the structure would mean a change in a few places, but now changing the structure would sorta only require changing the comonad instance.