Some type family applications in instances are fine actually
A typeclass instance that uses a type family is currently rejected unconditionally by GHC. But I believe there are special cases where it should be fine to accept them.
The basic idea is to think about the simplest possible case: if the type family is closed and the application is completely monomorphic. In this case, writing something like instance C (F Int Bool) where ...
should really mean exactly the same as if F Int Bool
was manually expanded by the user.
But I think we can go further, by classifying each type family parameter as whether the type family is parametric in that parameter. So something like
type family F a b where
F Int b = Maybe b
F Bool b = [b]
is not parametric in a
, but is parametric in b
. And so an instance instance C (F Int x)
could, again, be expanded by the user manually into instance C (Maybe x)
, so why not offer to do it for them.
For open type families, we can't mark any parameter as parametric, but it should still be fine to allow the degenerate case of fully monomorphic applications; after all, GHC already rejects conflicting type family instance declarations.