You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- probably is, but foldable really means traversing in a linear order
125
-
-- with tree in principle we'd have to process each subtree in parallel
126
-
-- but we could implement foldable by first making a choice on how to traverse a tree and turn it into a list, and then performing the fold on the resulting list
123
+
||| This requires us traversing a tree in a linear order
124
+
||| This means we have to make a choice on which subtree to process first
125
+
||| Another way is to first implement a traversal of the tree, and
126
+
|||then use that
127
127
public export
128
128
FoldableBinTreeLeafwhere
129
129
foldr f z (Leaf leaf) = f leaf z
130
-
foldr f z (Node_ leftTree rightTree) =?oo_1 where
131
-
leftTreeRes: acc
132
-
leftTreeRes =foldr {t=BinTreeLeaf} f z leftTree
133
-
rightTreeRes =foldr {t=BinTreeLeaf} f z rightTree
130
+
foldr f z (Node() leftTree rightTree) =
131
+
-- Process left first, i.e. fold right with z, then use that
132
+
-- as accumulator for left
133
+
let rightResult =foldr {t=BinTreeLeaf} f z rightTree
0 commit comments