GHC should include the missing pattern in runtime errors for pattern match failure
Motivation
When one omits a pattern in a pattern match, GHC knows what patterns are missing, and is happy to tell you if you enabled -Wincomplete-patterns
. However, when a pattern match fails at runtime, one gets simply Non-exhaustive patterns in function nth
. This isn't helpful, and we can do better.
Proposal
When GHC is generating code and there are patterns not handled, it should enumerate the specific patterns that are missing, and generate different cases for each one, with error messages that include the pattern. The actual value shouldn't be printed into the error message, since that might force the wrong things and requires a Show instance and all that; but GHC can already generate the missing pattern in a message, because it does so with -Wincomplete-patterns
. So it should really do that for all missing patterns, at compile time, and then generate runtime errors with those strings in them.