error-messages icon indicating copy to clipboard operation
error-messages copied to clipboard

Don't suggest adding constraints to methods and/or functions from other packages

Open noughtmare opened this issue 2 years ago • 0 comments

This stackoverflow question shows an error message with a very inappropriate suggestion:

src/LatticePoint.hs:12:14: error:
    • No instance for (Eq a)
      Possible fix:
        add (Eq a) to the context of
          the type signature for:
            fmap :: forall a b. (a -> b) -> LatticePoint a -> LatticePoint b
    • When checking that instance signature for ‘fmap’
        is more general than its signature in the class
        Instance sig: forall a b.
                      (Eq a, Eq b) =>
                      (a -> b) -> LatticePoint a -> LatticePoint b
           Class sig: forall a b.
                      (a -> b) -> LatticePoint a -> LatticePoint b
      In the instance declaration for ‘Functor LatticePoint’
   |
12 |     fmap ::  (Eq a, Eq b) => (a -> b) -> LatticePoint a -> LatticePoint b 
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think there are at least two things wrong with this message:

  1. It suggests changing code in another package
  2. It suggests changing methods of a type class

I'd estimate suggestions that do either of those are very rarely the right way to fix the problem.

My suggestion would be to at least stop this possible fix from being shown and if possible show a better explanation instead.

noughtmare avatar May 19 '22 13:05 noughtmare