[Haskell-beginners] How to "insert" a cross reference into a tree structure

Edward Z. Yang ezyang at MIT.EDU
Sun Dec 19 10:54:19 CET 2010


You can do this, but with some caveats; the technique is called tying the knot
[1].  However, if you decide to go subsequently change an Artist, any recursive
references to it must be updated too, and you will get very slow update.

> collection  = MusicCollection [direStraits, sting]
> direStraits = Artist "Dire Straits" [brothersInArms]
> brothersInArms  = Album "Brothers in Arms" [moneyForNothing]
> moneyForNothing = Track "Money for Nothing" [direStraits]

Is fine, laziness stops the infinite loop.

Related to editing values embedded deep in structures, but not related
to cross-references, you might find this post interesting:

    http://conal.net/blog/posts/semantic-editor-combinators/

Cheers,
Edward

[1] http://www.haskell.org/haskellwiki/Tying_the_Knot



More information about the Beginners mailing list