Talk:Tree datastructures: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 52: | Line 52: | ||
Depends, of course, on the implementation of equality in each language. For JS I have had to hand-write a recursive '''eq'''. Haskell's '''Data.Tree''' module includes a Tree instance for the Eq class. Python's (==) equality is recursive out of the box. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 13:27, 16 October 2019 (UTC) |
Depends, of course, on the implementation of equality in each language. For JS I have had to hand-write a recursive '''eq'''. Haskell's '''Data.Tree''' module includes a Tree instance for the Eq class. Python's (==) equality is recursive out of the box. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 13:27, 16 October 2019 (UTC) |
||
===Deriving a tree from a list of lines with their indent levels=== |
|||
For what its worth, a declarative description which is also a recursive algorithm might look something like: |
|||
<pre>If a forest is understood as a list of trees, |
|||
then the forest structure of an indented outline is either |
|||
an empty list, |
|||
(if the outline contains no lines) |
|||
or a list with a tree at its head, and a tail which is a forest. |
|||
The head tree: |
|||
- has the first line of the outline as its value |
|||
- and has a child list |
|||
which is the forest structure of all the lines: |
|||
- following the first line, |
|||
- and preceding the next peer |
|||
(the next line that shares the first's indent level) |
|||
The tail forest has the structure of the remaining outline, |
|||
- from the next line which shares the indent level of the first line, |
|||
- to the last line of the outline.</pre> |