Por que o GHC está reclamando sobre padrões não exaustivos?
Quando eu compilar o seguinte código com GHC (usando o-Wall
bandeira):
module Main where
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
insert :: (Ord a) => a -> Tree a -> Tree a
insert x EmptyTree = Node x EmptyTree EmptyTree
insert x (Node a left right)
| x == a = Node a left right
| x < a = Node a (insert x left) right
| x > a = Node a left (insert x right)
main :: IO()
main = do
let nums = [1..10]::[Int]
print . foldr insert EmptyTree $ nums
O GHC reclama que a correspondência de padrõesinsert
não é exaustivo:
test.hs|6| 1:
|| Warning: Pattern match(es) are non-exhaustive
|| In an equation for `insert': Patterns not matched: _ (Node _ _ _)
Por que o GHC está emitindo este aviso? É bastante óbvio que o padrão que o GHC reclama é tratadoinsert x (Node a left right)
.