haskell / haskell/error-messages

Non-exhaustive pattern match warning with guards

Open
#20 7 comments 0 reactions 0 assignees View on GitHub
status:Composing error message tool:GHC type:error-message
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

In [this stackoverflow question](https://stackoverflow.com/questions/69197294) the asker presents this code:

```haskell
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
```

Which produces the following warning (with `-Wall`):

```
Test.hs:5:1: warning: [-Wincomplete-patterns]
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 _ _ _))
|
5 | insert n Leaf = Node n Leaf Leaf
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
```

The list of "patterns not matched" here is strange, it seems to me that the pattern not matched is just `_ (Node _ _ _)` and I think it should also mention something about the guards.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.