[Haskell-cafe] How to represent a board?
chriswarbo at googlemail.com
Fri Jun 20 15:53:15 UTC 2014
Alexander Vieth <alex at lagoa.com> writes:
>> In many languages a NxN array seems like a good pick. In Haskell,
>> most would translate that into lists of lists. I know I
>> have. However, traversing those lists to get a position, calculate
>> where a piece or agent could go, etc., feels awkward and
>> unefficient. Beside the point already made, we have no type safe
>> guarantee that our 64x64 won't become a 63x63 + 65x1 board due to
>> some misbehaving function.
> Perhaps choosing a zipper-like representation, in which all adjacent
> places on your board can be found without any traversal, would make
> the usage less awkward and more efficient.
I thought of zippers too, although their simplicity suffers when moving
from 1D lists to 2D lists-of-lists.
Comonads are possibly related. They're certainly useful for cellular
automata, which are effectively zero-player board games.
More information about the Haskell-Cafe