More suitable data structure needed

paul@theV.net paul@theV.net
Wed, 21 Aug 2002 15:29:30 +0800


On Wed, Aug 21, 2002 at 04:44:03PM +0930, Dr Mark H Phillips wrote:
> 
> I would like to represent this structure in Haskell, but 
> am not sure quite the best way of doing it.  (I am relatively
> new to Haskell.)  I think I want to do something like:
> 
> [
> [(2,5),[(1,3),[(2,0)]],
>        [(1,2),[(1,1),[(1,0)]]],
>        [(3,1)]],
> [(1,5),[(2,4),[(2,0)]],
>        [(1,4),[(1,3),[(1,1),[(1,0)]]],
>               [(2,2),[(1,0)]],
>               [(1,2),[(2,1)]]],
>        [(2,3),[(1,2),[(1,0)]],
>               [(2,1)]],
>        [(1,3),[(2,2),[(1,1)]]],
>        [(4,2)]]
> ]
> 
> But what is the best way to represent this in Haskell?  (Clearly
> I can't do exactly this, because Haskell requires all list elements
> to be of the same type.)

This kind of lists do not have a concrete type, therefore cannot
be represented in Haskell. I'd suggest you try a tree structure
for your data. Something like a Left and Right branch, Left branch
goes down to another row of the same level, Right branch goes to
to right column.

Regards,
.paul.