我有以下代码:
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
对我来说,这个insert
函数似乎是详尽的 wrt 可能的参数模式,但是当我尝试用 ghc 编译时,它说
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 _ _ _))
你能帮我看看为什么吗?