Report class constraints when reporting type errors.
GHC does not report classes when it reports type errors, making it hard to fix bugs.
Steps to reproduce
Take a function like e.g. Hedgehog's
sample :: MonadIO m => Gen a -> m a
sample :: ()
You will get an error such as:
• Couldn't match expected type ‘()’ with actual type ‘Gen a0 -> m0 a0’ • Probable cause: ‘Gen.sample’ is applied to too few arguments In the expression: Gen.sample :: () In an equation for ‘x’: x = Gen.sample :: () In the expression: do putStrLn "Hello, Test!" let x = ... return () | 16 | let x = Gen.sample :: () | ^^^^^^^^^^
I'd like to have GHC report that
m0 above is a
MonadIO. That would have saved me a lot of trouble by tipping me off that it's just something I can use at the top level of the
do block in
I understand the code that had an error is a little funny, it's just a minimal case I could come up with to report here that is still somewhat practical.
I feel like I've encountered this many times before, but it only now occurred to me that it would be much better if GHC actually reported the classes.
- GHC version used: 8.6.3