Overlapping instances and type families
Summary
The overlapping instances message can be confusing when the cause of overlapping instances is a type family.
Steps to reproduce
type family Fam (a :: Type) :: Type
class Cls (a :: Type)
instance {-# OVERLAPPABLE #-} Cls a
instance Cls (Maybe a)
foo :: Cls (Fam Int) => Int
foo = 42
bar :: Int
bar = foo
The error message is
• Overlapping instances for Cls (Fam Int)
arising from a use of ‘foo’
Matching instances:
instance [overlappable] Cls a
-- Defined at /home/zliu41/ana/overlapping/A.hs:9:31
instance Cls (Maybe a)
-- Defined at /home/zliu41/ana/overlapping/A.hs:10:10
(The choice depends on the instantiation of ‘’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
Expected behavior
It should either remove The choice depends on the instantiation of ‘’
, or better yet, replace it with The choice depends on the expansion of ‘Fam Int’
.
Environment
- GHC version used: 9.3.20211002