There are a few different kinds of trees, but if you only need to
store data on the leaves, that representation will work. As for your
sumTree function, you are indeed missing a case...consider sumTree
(Leaf 3)! Once you deal with that case, the other two can actually be
combined (since sum [] = 0).
2008/7/21 Ryan Bloor [EMAIL PROTECTED]:
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!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe