“Illegal type synonym family application in instance” is too strict in the presence of injective type families
GHC rejects the following instance, complaining about the use of a type synonym family in the instance head:
type family Fam a = b | b -> a where
Fam a = [a]
class Foo a
instance Foo (Fam a)
However, this seems too strict to me, since the parameter of Foo
is determined by an (closed) injective family. If I tweak the instance slightly to inline the type instance, GHC accepts the instance:
instance Foo [a]
It seems to me that, due to the functional dependency, these two instances are completely equivalent. Therefore, GHC should accept the first instance.
This is similar to an old ticket, #14046, but that did not involve injective type families, so the transform required was more complex. I’m pretty sure the addition of injective type families changes things, making the two actually equivalent.