[Haskell-cafe] I just don't get it (data structures and OO)
vincent at kraeutler.net
Sun Jun 3 10:56:03 EDT 2007
> This is very informative, and easier to grasp for such a newbie as me.
> So the idea is to take the "changing function" down the chain, i knew
> this couldn't be that hard !
> Still this requires indeed to think different, I guess i'm up for
> quite a few exercises in order to wrap my mind around this.
> That's the kind of information that's missing from all these tutorials
> i found around the web.
> Thank you,
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
for what it's worth, i find it easiest to think about it this way:
assume you want to update a planet, i.e. you want to apply
changeP :: Planet -> Planet
to one planet in your system.
the important step is then to invoke wishful thinking (viz. SICP), and
assume you can partition your data structure into two parts, the one
that stays constant, and the one that is changed, i.e.
partition :: Universe -> (Rest, Planet)
with a corresponding inverse operation
recombine :: (Rest, Planet) -> Universe
So after the partitioning, updating the planet of interest is very easy
changeP' (rest, planet) = (rest, changeP planet)
rolling the partitioning, updating and recombination into one, we get
update u = recombine (changeP' (partition u))
The second step is then to find out how to do the partitioning and
recombination easily and efficiently. For one very generic way to do
this, i would recommend that you read up on the Zipper data structure [1-3].
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 249 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070603/2a493edd/signature.bin
More information about the Haskell-Cafe