[Haskell-cafe] I just don't get it (data structures and OO)

Vincent Kraeutler vincent at kraeutler.net
Sun Jun 3 10:56:03 EDT 2007


Phlex wrote:
> 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,
> Sacha
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

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
to accomplish:

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].

kind regards,
v.

[1] http://en.wikibooks.org/wiki/Haskell/Zippers
[2]
http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf
[3] http://cgi.cse.unsw.edu.au/~dons/blog/2007/05/17#xmonad_part1b_zipper



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
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 mailing list