Talk:Tree from nesting levels: Difference between revisions

Content added Content deleted
Line 72: Line 72:
To put this in a Python notation, if we '''start''' with one of these forests ('''lists''' of trees), mapping over each of its members with a foldTree catamorphism, passing a function like this to it:
To put this in a Python notation, if we '''start''' with one of these forests ('''lists''' of trees), mapping over each of its members with a foldTree catamorphism, passing a function like this to it:


<pre>def levelList(x):
<lang python>def levelList(x):
'''A Tree in which is node is a tuple of two values:
'''A Tree in which each node is a tuple of two values:
A possible integer, and a list of trees.
A possible integer, and a list of trees.
(Int or None, [Tree])
(Int or None, [Tree])
Line 82: Line 82:
else:
else:
return (x.get('Just', 0), concat(xs))
return (x.get('Just', 0), concat(xs))
return go</pre>
return go</lang>


We can obtain a self-consistent representation of these forests as lists of tuples, in which the first value is a kind of sum type (Int or None), and the second value is itself a (possibly empty) forest:
We can obtain a self-consistent representation of these forests as lists of tuples, in which the first value is a kind of sum type (Int or None), and the second value is itself a (possibly empty) forest: