Suppose I have a type with many constructors and a few pattern synonyms. I'd like to use pattern synonyms to replace a few of the constructors. How can I write the necessary COMPLETE pragma(s) without having to write out all the constructors by hand and risk falling behind if more are added?
How can I write COMPLETE pragmas for types with many constructors?
131 views Asked by dfeuer At
1
Using the
th-abstractionpackage, this is quite simple. Some throat clearing:Using
reifyDatatype, we can get info about a type, and extract a list of the names of its constructors. Then we simply need to add on the patterns we want and remove the constructors we don't want.Now the module defining the datatype just needs to import this one, and say
I recommend invoking
completeWithButWithoutat the very end of the module, to prevent the splice from splitting the module.