Skip to content

WIP: An initial attempt at type-directed COMPLETE pragmas.

cgibbard requested to merge obsidiansystems/ghc:cg-type-directed-complete into master

This deals with #14422 and implements the GHC proposal at https://github.com/ghc-proposals/ghc-proposals/pull/399.

The signature in a COMPLETE pragma is repurposed to be a type that must unify with the type of the scrutinee in order for the given pragma to apply to a pattern match, if it is present.

I'm still not entirely confident that I understand the pattern-match checker well enough to have done this correctly on the first try, so careful review would be appreciated.

Certainly it could use some more tests, and it's also not strictly backward-compatible with the existing syntax (which parses a tycon rather than a type), though the existing syntax is vestigial and does not really do anything at present, since the pragmas are no longer attached to a particular tycon.

There are various ways we could adjust this feature to make the potential impact on existing code smaller, though perhaps it would be good to get some information about what the impact actually is first. In any case, code should be easy to fix, and in all the cases where I ran into it, it was obvious from the error message what to do.

Edited by cgibbard

Merge request reports