[Haskell-beginners] Does Haskell have a function that creates a list corresponding to the nodes in a tree, from the leaf node to the root node?

Andy Elvey andy.elvey at paradise.net.nz
Mon Jun 13 07:49:38 CEST 2011


Hi all.....
This "tying the knot" looks interesting..... :)
The example that Markus gave immediately reminded me of a BNF grammar 
(which is very much a recursive-ish thing).
Does anyone know if "tying the knot" has been used in parsers?  Just 
curious..... it'd seem to be a useful thing to use in that area.
- Andy


On 13/06/11 13:02, KC wrote:
> Hi Roger:
>
> It depends on what kind of tree you have and what kind of information
> you expect to give the tree to find the leaf node.
>
> If it's a binary search tree (BST) and you have the leaf key value
> then use "find leafKey" and keep prepending the nodes you visit to the
> list.
>
> I might call the function: parents or ancestors. :)
>
>
>
> On Sat, Jun 11, 2011 at 5:28 AM, Costello, Roger L.<costello at mitre.org>  wrote:
>> Hi Folks,
>>
>> I am implementing the following function in another language. I want to see if Haskell already has a function that does this; if so, I want to use the Haskell function name rather than inventing my own.
>>
>> Here is the function that I am implementing: consider a tree data structure. I pass to the function one of its leaf nodes. The function returns a list containing that leaf node as the first element of the list, the leaf node's parent as the second element of the list, ..., the tree's root node as the n'th element of the list. (The list consists of all the nodes from the leaf node to the root node)
>>
>> Does Haskell have a function that does this?
>>
>> If not, and you were to define a function for this, what name would you give to the function?
>>
>> /Roger
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110613/8f3fad8a/attachment.htm>


More information about the Beginners mailing list