Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete pattern warning when matching both Nil and Cons #107

Open
flhorizon opened this issue Nov 9, 2022 · 1 comment
Open

Incomplete pattern warning when matching both Nil and Cons #107

flhorizon opened this issue Nov 9, 2022 · 1 comment

Comments

@flhorizon
Copy link

Hello, I'm getting this warning for a pattern usage like:

foo :: DList a -> IO ()
foo Nil = putStrLn "empty!"
foo (Cons x xs) = print $ x:xs
warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘foo’:
        Patterns not matched: _ 

My understanding using pattern synonyms, is that the implementer needs to tell the compiler which pattern set should be considered as complete:

{-# COMPLETE Nil, Cons #-}

Would you accept a PR for that?

@spl
Copy link
Owner

spl commented Nov 10, 2022

Would you accept a PR for that?

Certainly! Thanks for offering!

I just checked briefly to see when it was added to GHC. It seems to appear in the documentation of 8.2.1. It's absent from the 8.2.1 release notes but appears in the 8.2.2 release notes.

I would ideally like a test that demonstrates no incomplete pattern warning (-Wincomplete-patterns) when COMPLETE is used. Perhaps the warning can be turned into an error that would cause compiling to fail. Also, the test should ideally pass for all versions of GHC that support COMPLETE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants