There is also the grid package on hackage that has support for a number of different grid shapes.

Ben


On Fri, Jun 20, 2014 at 5:12 PM, Daniel Trstenjak <daniel.trstenjak@gmail.com> wrote:


Hi Rafael,

> Having in mind the sort of operations such games have to make on boards, I ask:
> what are the best representations for a board in Haskell?

What works pretty nicely is using a one dimensional Data.Vector[1] to represent
your board, a tuple (x, y) to represent a position on the board and then using
a lens[2] to transform the tuple (x, y) into an index of the one dimensional Data.Vector.

You can then write code like:

-- get board value at position (1, 2)
board ^. atCoord (1, 2)

-- set board value at position (1, 2)
board & atCoord (1, 2) .~ newValue


Having a one dimensional vector has the advantage, that's a lot nicer to e.g. map or fold over it.

In the toy example hsbot[3] I used this kind of representation.


Greetings,
Daniel

[1] https://hackage.haskell.org/package/vector
[2] https://hackage.haskell.org/package/lens
[3] https://github.com/dan-t/hsbot
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe