hlint icon indicating copy to clipboard operation
hlint copied to clipboard

Is it possible to write hints for typeclass instances?

Open telser opened this issue 2 years ago • 1 comments

It doesn't seem that this is possible currently, but perhaps I'm missing something. There are a couple of use cases for this that have come up for me.

One is being able to enforce that enumFrom is defined in an instance of Enum, as we've encountered trouble in a couple of codebases now where an expectation with arises with the default of an infinite enumeration, but we more frequently have finite ones.

The second is to be able to say that '(/=)' is not defined, to prepare for that becoming not a typeclass method. This second use case would be fantastic for the HF stability working group to be able to promote as way to help the community smooth over transitions like this in a general way.

telser avatar Jan 09 '23 14:01 telser

Not currently. There are two ways to go to add it:

  1. Add a generic mechanism inside HLint to require that a class instance is/isn't defined.
  2. Add custom hints built in at the Haskell layer that validate the type class.

Given the two instances you have both are built in to the base library, doing a custom hint in the Haskell layer seems reasonable. I guess I wonder if there are more instances you might want to hint in the future?

ndmitchell avatar Feb 05 '23 16:02 ndmitchell