Confusing error writing an instance of a non-class type
Summary
Messing up an instance head can lead to very confusing errors.
Steps to reproduce
I was trying to write a Functor
instance for a type, but accidentally omitted the word Functor
from the instance head.
data Foo m a
instance Foo m where
fmap _ x = case x of
GHC told me
error:
‘fmap’ is not a (visible) method of class ‘Foo’
Huh?
Expected behavior
I would expect GHC to tell me that Foo
is not a class and therefore cannot have any instances. I would imagine this could be handled in the renamer.
Environment
- GHC version used: 9.4.3
Optional:
- Operating System:
- System Architecture:
Edited by David Feuer