[Haskell-cafe] Reconstructing a tree from a list of its paths (to leaves)

Arnaud Bailly arnaud.oqube at gmail.com
Tue Apr 10 13:44:13 CEST 2012


Hello Twan,
I have a rather clear idea of how I would do it (in Haskell or in
Java), but I feel this is something quite common that should have
already been handled in other contexts (eg. XML/XPath stuff, JSon, CSS
?), hence my question which was admittedly not clear enough.

Anyway, thanks a lot for your detailed answer and your code.

Best regards,
Arnaud

On Tue, Apr 10, 2012 at 12:26 PM, Twan van Laarhoven <twanvl at gmail.com> wrote:
> On 10/04/12 09:55, Arnaud Bailly wrote:
>>
>> Hello,
>> I am manipulating labeled multiway trees, some kind of "lightweight"
>> XML notation. One thing I would like to be able to do is manipulating
>> a tree as a list of (Path, Value). Generating such a list is easy but
>> I am a little bit surprised to find it harder to reconstruct a tree,
>> given such a list assuming some sensible properties (list is ordered,
>> for example).
>>
>> I got the intuition this has already been tackled in one way or
>> another in a functional setting in Haskell (I code in Java but using
>> mostly functional constructs), but don't know where to look.
>
>
>
> The haskell solution would be to consider first how to turn a single
> (Path,Value) into a tree. Then you just combine these trees for all the
> paths by taking their union. I attached some code.
>
>
>
> Twan
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list