Pattern match warnings suggest internal constructors
Summary
The pattern-match exhaustiveness checker displays a list of non-matched constructors which are internal and shouldn't be displayed. I have checked the issues tagged with "pattern match warnings" in the issue tracker and haven't found a similar issue.
Steps to reproduce
Compile the following snippet with -Wall
or -Wincomplete-patterns
.
module Compiler where
import Data.Map
type Var = String
data Prim = Mult | Add
data Term = Var Var
| BinaryPrim Term Prim Term
type Heap = Map Var Term
type State = (Heap, Term)
stepVar :: State -> Maybe State
stepVar (h, Var v) = if member v h
then Just (h, h ! v)
else Nothing
This produces the following warning:
Compiler.hs:17:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘stepVar’:
Patterns not matched:
((Data.Map.Internal.Bin _ _ _ _ _), (BinaryPrim _ _ _))
(Data.Map.Internal.Tip, (BinaryPrim _ _ _))
|
17 | stepVar (h, Var v) = if member v h
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Expected behavior
The internal implementation of Map in terms of Tip and Bin should not be made visible to the user. Importing the internal modules and pattern matching on Bin and Tip is almost always the wrong solution, and especially confusing for newcomers. The expected warning should look like this:
Compiler.hs:17:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘stepVar’:
Patterns not matched:
(_, (BinaryPrim _ _ _))
|
17 | stepVar (h, Var v) = if member v h
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Environment
- GHC version used: 8.10.4