[Haskell-cafe] ANN: ban-instance-0.1.0.1
jack at jackkelly.name
Fri Nov 8 06:51:50 UTC 2019
I have just pushed an initial release of ban-instance to Hackage.
ban-instance uses template haskell to generate compile errors for
typeclass instances that should not exist:
-- Declare that Foo should never have a ToJSON instance
$(banInstance [t|ToJSON Foo|] "why ToJSON Foo should never be defined")
The custom errors then say why an instance is banned:
• Attempt to use banned instance (ToJSON Foo)
Reason for banning: why ToJSON Foo should never be defined
Instance banned at [moduleName] filePath:lineNumber
We have found this useful to prevent definition of ToJSON/FromJSON
instances on core data types, as this forces programmers to instead
place the serialisation instances on newtypes at the serialisation
GitHub issues and PRs are welcome. In particular, there are currently
a few limitations:
1. There is currently no support for classes with associated types or
associated data types;
2. It would be great to generate haddocks for banned instances, marking
them as such; and
3. Type quotations [t|...|] do not support free variables (GHC#5616).
Nevertheless, I hope that it is useful.
More information about the Haskell-Cafe