I’m trying to write a simple Haskell function that distinguishes between an empty list and a non-empty list. Here’s my code:
{-# LANGUAGE OverloadedLists, RebindableSyntax #-}
import Prelude (Int, IO, putStrLn)
import GHC.Exts (IsList (..))
doneVsItems :: [Int] -> IO ()
doneVsItems [] = putStrLn "Done"
doneVsItems (p:ps) = putStrLn "Items"
main :: IO ()
main = doneVsItems []
However, when I compile the code with -Werror=incomplete-patterns enabled, I get the following error:
error: [GHC-62161] [-Wincomplete-patterns, Werror=incomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘doneVsItems’:
Patterns of type ‘[Int]’ not matched: []
|
7 | doneVsItems [] = putStrLn "Done"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
I explicitly pattern match on both the empty list ([]) and the non-empty list ((p:ps)), so I don’t understand why GHC is saying the pattern match is non-exhaustive. What am I missing here?
It looks like OverloadedLists, and RebindableSyntax no longer work together. I've created an issue here.
This is a bug with GHC. The extensions OverloadedLists
, and RebindableSyntax
no longer work together. See steps to reproduce.