[Haskell-cafe] Re: I just don't get it (data structures and OO)
Christopher Lane Hinson
lane at downstairspeople.org
Sun Jun 3 10:01:34 EDT 2007
> Let's say i have a deep nested data structure.
> Universe containing galaxies, containing solar systems, containing
> planets, containing countries, containing inhabitants, containing
Oh. I had /exactly/ this problem. If you use separate types (i.e. a
newtyped integer, acting kindof like a pointer) to represent (1) the
identity and (2) the state of the object, you can use a separate data
structure that remembers which object is inside which other object.
Where "InsidenessMap a b c" represents a relationship where b's are inside
a's, and b's have a state of c. Then, you need to declare a separate
InsidenessMap for each possible relationship, but this ensures that you'll
never put a galaxy inside a solar system. Or you can make 'a' be a
reference to any type of object; there are options.
But, you just update this structure once, with no thought of recursively
updating a heterogenous tree of data.
It may not be the best solution, but if I knew of something better I
would be using the better thing instead.
More information about the Haskell-Cafe