[Haskell-cafe] ANN: ban-instance-0.1.0.1
Jack Kelly
jack at jackkelly.name
Fri Nov 8 06:51:50 UTC 2019
I have just pushed an initial release of ban-instance[1] 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
boundary.
GitHub issues and PRs are welcome[2]. 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.
Best,
-- Jack
[1]: http://hackage.haskell.org/package/ban-instance-0.1.0.1
[2]: https://github.com/qfpl/ban-instance/
More information about the Haskell-Cafe
mailing list