
Henning Thielemann
On Thu, 28 May 2020, Ben Gamari wrote:
Henning Thielemann
writes: What linter can easily catch "instance Foldable ((,) a)"?
GHC cannot warn about it, so far.
Another solution would be to separate 'base' from GHC. I could then work with a patched 'base' with forbidden "instance Foldable ((,) a)".
For what it's worth, I suspect there are a few solutions to the problem of disallowing use of particular instances which may be close-at-hand:
* Providing a compiler flag or pragma to "poison" an instance, locally preventing the compiler from using it as evidence; this would require a GHC proposal and may not be entirely trivial to implement, but it's certainly feasible.
Indeed. All we need is someone to implement. Admittedly, I don't have much insight into how difficult this would be. Richard or Simon would likely be more helpful in this regard.
* Providing a GHC source plugin that would look for dictionaries of type (e.g.) Foldable ((,) a) in the desugared Core of a module and report them as errors
Interesting idea. Or would it be better implemented in a type-checker plugin?
That would be another approach but I don't believe this is possible with our current typechecker plugin mechanism.. Specifically, I don't think you can currently hide existing instances. In principle your plugin could solve the unwanted instance with a TypeError but I'm not sure whether this would work reliably with GHC's current implementation: I believe that typechecker plugins are currently a fallback looked at after the usual paths have failed. Moreover, even if it does work we don't that guarantee solver behavior won't change in the future. Cheers, - Ben