Hi
Basically I've made a polymorphic tree data type and I need a way of counting the number of elements in a given tree. Here's the declaration for my Tree data type:
data Tree a = Empty
| Leaf a
| Node (Tree a) a (Tree a)
deriving (Eq, Ord, Show)
So I can define a tree of Ints like this:
t :: Tree Int
t = Node (Leaf 5) 7 (Node (Leaf 2) 3 (Leaf 7))
However, I need a function to count the number of elements in one of these lists. I've defined this recursive function but I get the error "inferred type is not general enough":
size :: Tree a -> Int
size Empty = 0
size (Leaf n) = 1
size (Node x y z) = size x + size y + size z
Is there something here I shouldn't be doing?
Thanks
Ben