You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I dunno if it belongs here, but COMPLETE pragmas are a bit painful to write by hand for types with many constructors, especially when constructors can be added or removed from time to time. Using th-abstraction, it's easy to fix this. Without th-abstraction, I don't wanna.
importLanguage.Haskell.TH.Datatype (DatatypeInfo (..), ConstructorInfo(..), reifyDatatype)
importLanguage.Haskell.TH (Q, Dec, Name, pragCompleteD)
importData.List ((\\))
--| Produce a @COMPLETE@ pragma for a type with many constructors,-- without having to list them all out.---- @completeWithButWithout ''T ['P] ['C1, 'C2]@ produces a @COMPLETE@-- pragma stating that pattern matching on the type @T@ is complete with-- with the pattern @P@ and with all the constructors of @T@ other than-- @C1@ and @C2@.completeWithButWithout::Name-> [Name] -> [Name] ->Q [Dec]
completeWithButWithout ty extra_patterns excl_constrs =do
di <- reifyDatatype ty
let constrs =map constructorName (datatypeCons di)
(:[]) <$> pragCompleteD (extra_patterns ++ (constrs \\ excl_constrs))
(Just ty)
For truly enormous datatypes, (\\) could be swapped out in favor of something that uses the Ord Name instance.
The text was updated successfully, but these errors were encountered:
Yeah, seems useful! I'd merge a PR adding such a thing. I suppose putting it in its own module makes sense as TH.Utilities is a grab-bag of utilities useful for writing TH code
I dunno if it belongs here, but
COMPLETE
pragmas are a bit painful to write by hand for types with many constructors, especially when constructors can be added or removed from time to time. Usingth-abstraction
, it's easy to fix this. Withoutth-abstraction
, I don't wanna.For truly enormous datatypes,
(\\)
could be swapped out in favor of something that uses theOrd Name
instance.The text was updated successfully, but these errors were encountered: