[erlang-questions] Tuples referencing each other problem

Richard A. O'Keefe ok@REDACTED
Fri Sep 22 02:37:52 CEST 2017



On 22/09/17 2:23 AM, Grzegorz Junka wrote:
> To answer your question Richard, I don't actually need a cyclical
> structure. As I mentioned, this is a simplification of a more specific
> problem. I didn't want to describe all the specifics to ask a question.
> I need to design a tree, a variant of a HAMT tree, but which can be
> traversed in both directions, from the root to leafs and from leafs to
> the root (independently, i.e. starting from a reference to a leaf rather
> than recursively).

Of course this pushes back the question a further step.
Why do you want to traverse the tree in both directions?

Might the "zipper" approach be any use?

If you want references to leaves, such references could be paths.
I used that technique once in a programming language that used
reference counting, so that link cycles meant no collection.
(Yes, I know modern reference-based collectors have solved that
problem.)  I've also used that technique for processing XML in
a pure functional language.

In an imperative context, that doesn't work very well because the
tree structure might change.  The DOM suffers from trying to make
this "work" in some sense, but trying to iterate over a graph
while something else is changing it is never going to be easy.

It is possible that the Haskell "Functional Graph Library"
may be relevant to your needs.




More information about the erlang-questions mailing list