hi
I was curious as to whether my implementation of a Rose Tree and a sumTree function was correct. The aumTree adds up the elements of a tree.
data Tree a = Leaf a | Node [Tree a]
sumTree :: Tree Int -> Int
sumTree (Node []) = 0
sumTree (Node xs) = sum (map sumTree xs)
The problem with this is I get a pattern matching error. Am I representing trees right... see below.
Also, would an empty tree be represented by ... Node [] with this implementation?
How would I represent a tree of the form... Tree (Node 2(Node 6 Empty Empty) Empty) taken from a binary one.
Like this? Node [ [Leaf 2], Node [ Leaf 6,Node[],Node[] ], Node[] ]
Ryan
Find out how to make Messenger your very own TV! Try it Now!