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: |
||
<lang python> |
<lang python># levelList :: Tree (Int|None) |
||
def levelList(x): |
|||
'''A Tree in which |
'''A Tree in which is 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 81: | Line 82: | ||
return (None, concat(xs)) |
return (None, concat(xs)) |
||
else: |
else: |
||
return (x.get('Just', 0), concat(xs)) |
return [(x.get('Just', 0), concat(xs))] |
||
return go</lang> |
return go</lang> |
||
Line 87: | Line 88: | ||
<lang python>[] |
<lang python>[] |
||
[(1, [2, [None, [4, []]]])] |
[[(1, [(2, [(None, [(4, [])])])])]] |
||
[(None, [None, [3, []]]), (1, [None, [3, []]]), (1, [])] |
[[(None, [(None, [(3, [])])])], [(1, [(None, [(3, [])])])], [(1, [])]] |
||
[(1, [2, [3, []]]), (1, [])] |
[[(1, [(2, [(3, [])])])], [(1, [])]] |
||
[(None, [None, [3, []], 2, []]), (1, [None, [3, []]])] |
[[(None, [(None, [(3, [])]), (2, [])])], [(1, [(None, [(3, [])])])]] |
||
[(None, [None, [3, [], 3, [], 3, []]]), (1, []), (1, [None, [3, [], 3, [], 3, []]])]</lang> |
[[(None, [(None, [(3, []), (3, []), (3, [])])])], [(1, [])], [(1, [(None, [(3, []), (3, []), (3, [])])])]]</lang> |
||
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 14:00, 4 February 2021 (UTC) |
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 14:00, 4 February 2021 (UTC) |