[Haskell-cafe] Re: Infinite grid
ChrisK
haskell at list.mightyreason.com
Mon Dec 29 19:34:05 EST 2008
Luke Palmer wrote:
> On Mon, Dec 29, 2008 at 3:55 PM, Martijn van Steenbergen
> <martijn at van.steenbergen.nl <mailto:martijn at van.steenbergen.nl>> wrote:
>
> Hello,
>
> I would like to construct an infinite two-dimensional grid of nodes,
> where a node looks like this:
>
> data Node = Node
> { north :: Node
> , east :: Node
> , south :: Node
> , west :: Node
> }
>
>
> in such a way that for every node n in the grid it doesn't matter
> how I travel to n, I always end up in the same memory location for
> that node.
>
>
> No problem:
>
> let n = Node n n n n in n
>
> But you probably want some additional data in each node, also, in which
> the problem becomes harder.
The solution very much depends on how the data is initialized / computed / obtained.
Note that one can put an IORef into the Node to allow for mutable value.
Also, see if you need something akin to mkDList at
http://haskell.org/haskellwiki/Tying_the_Knot
Cheers,
Chris
More information about the Haskell-Cafe
mailing list