A binary tree is either a branch, a leaf, or an empty tree
data Tree a = Branch (Tree a) (Tree a) | Leaf a | Empty
Since there are three options for the tree type, we must cover all three cases:
treeSize :: Tree a -> Integer treeSize Empty = 0 treeSize (Leaf l) = 1 treeSize (Branch b1 b2) = treeSize b1 + treeSize b2
Looks like polymorphism in C++, but the function only has one type.
Without worrying about the type signature, alter this function to sum up all the elements in the tree (assuming they're numbers).