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 the best and worst places on the planet
http://clk.atdmt.com/UKM/go/101719807/direct/01/
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe