Don't suggest turning on typeclass extensions that don't help
Returning to the example from: https://github.com/haskell/error-messages/issues/42 , when FlexibleInstances is already on we get the not-that-bad error
ghci> 1 + [2,3]
<interactive>:6:1: error:
* No instance for (Num [a0]) arising from a use of `it'
* In a stmt of an interactive GHCi command: print it
But when FlexibleInstances is not yet on, we instead get an error suggesting we turn it on!
I think that errors which suggest some typeclass extension should be turned on (at call sites, not instance declarations) should first check if the extension would help -- i.e. if the code would typecheck with the extension. If it still would not typecheck with the extension, then the error message should be about the failure to typecheck, not the extension that requires it.
This seems like a reasonable-to-implement principle which could potentially improve a broad class of error messages.
There is a danger here. If I say
x :: Maybe 5
x = Just 5
I currently get an error saying that 5 is an illegal type. (It also suggests enabling DataKinds.) With DataKinds on, I get a kind error involving GHC.Types.Nat. I actually think "5 is an illegal type" is better.
More generally, if we pretend as if an extension were on sometimes -- just to see what would happen -- we might get error messages that really require a deeper understanding of the extended language than the user has at the moment.
I agree that, in this case, the error around the extension is worse than the type error. But I think that's best decided on a case-by-case basis.
Sure. I specifically suggested "typeclass extensions" because I think that those will all work well. But I don't have a perfect heuristic in mind.