3 ms·
If you use a the right representation of the board in Haskell then you don't have to write a function to calculate the next generation at all, you can just use
by lgas 7y ago
If you use a the right representation of the board in Haskell then you don't have to write a function to calculate the next generation at all, you can just use Comanadic extend, as Chris Penner does here: https://github.com/ChrisPenner/conway/blob/master/src/Conway.hs#L53 https://github.com/ChrisPenner/conway/blob/master/src/Conway...
- kragen 7y agoWhile this code is awesomely mindbending, it does seem to be limited to a 20×20 grid, rather than being applicable to grids of any size. Also, and correct me if I'm wrong here, it looks like it would take more than 5 minutes to write. The more interesting aspect, though, is that it seems to be organized in an almost totally different way from the APL code. I suggest that this is largely because the two languages foster very different approaches to problem-solving (though also I get that this is not the normal way to program Life in Haskell either).
- lgas 7y agoIt doesn't have to be a finite grid. Here is another comonadic implementation of Life with an infinite board: https://github.com/BartoszMilewski/GameOfLife/blob/master/Life.hs https://github.com/BartoszMilewski/GameOfLife/blob/master/Li... Either version would definitely take me more than five minutes to write, but then again it would take me more than five minutes to write the APL version too. For someone like Penner or Milewski the comonadic Haskell versions might be achievable in the five minute ballpark.
- kragen 7y agoThank you very much for posting both of these awesome links!