I'm kinda new to haskell
data Tree a = Leaf | Branch (Tree a) a (Tree a)
deriving (Show, Eq)
insert :: (Ord a, Eq a) => a -> Tree a -> Tree a
insert x Leaf = Branch Leaf x Leaf
insert x (Branch l v r)
| x <= v = Branch (insert x l) v r
| x > v = Branch l v (insert x r)
The code gives the following warning (but compiles):
app\Main.hs:10:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for `insert':
Patterns not matched:
_ (Branch Leaf _ Leaf)
_ (Branch Leaf _ (Branch _ _ _))
_ (Branch (Branch _ _ _) _ Leaf)
_ (Branch (Branch _ _ _) _ (Branch _ _ _))
|
10 | insert x Leaf = Branch Leaf x Leaf
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Technically speaking x <= v
and x > v
should cover all possible alternatives, but I'm having this warning. I's actually fixed if I use otherwise
in the second case, but shouldn't it work just like this?