I have the following code:
data Tree = Leaf | Node Int Tree Tree
deriving (Eq, Show, Read, Ord)
insert :: Int -> Tree -> Tree
insert n Leaf = Node n Leaf Leaf
insert n tree@(Node num lt rt)
| n < num = Node num (insert n lt) rt
| n > num = Node num lt (insert n rt)
| n == num = tree
To me, the insert
function seems to be exhaustive wrt the possible parameter patterns but when I try to compile with ghc, it says
Pattern match(es) are non-exhaustive In an equation for ‘insert’: Patterns not matched: _ (Node _ Leaf Leaf) _ (Node _ Leaf (Node _ _ _)) _ (Node _ (Node _ _ _) Leaf) _ (Node _ (Node _ _ _) (Node _ _ _))
Can you help me see why?