
8 May
2008
8 May
'08
7:13 p.m.
Edsko de Vries wrote:
sum :: Tree -> Int sum t = sum' [t] 0 where sum' [] acc = acc sum' (Leaf i : ts) acc = sum' ts $! (i + acc) sum' (Node l r : ts) acc = sum' (l : r : ts) acc
Because of $!, you should compare the Leaf case to foldl', not foldl. The Node case can be said to mimic a stack using heap resource.