Error warns about non-injectivity of injective type family
When I say
{-# LANGUAGE TypeFamilies, RankNTypes #-}
module Bug where
import GHC.Exts
type family F a = r | r -> a
type family G a :: Constraint
meth :: (G a => F a) -> ()
meth = undefined
I get
Bug.hs:10:9: error:
• Could not deduce: F a ~ F a0
from the context: G a0
bound by the type signature for:
meth :: G a0 => F a0
at Bug.hs:10:9-26
NB: ‘F’ is a type function, and may not be injective
The type variable ‘a0’ is ambiguous
• In the ambiguity check for ‘meth’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
meth :: (G a => F a) -> ()
The presence of G a
is critical for exhibiting this bug. If I replace G a
with Show a
the problem disappears.
This one was actually encountered in an attempt to do Useful Work, not just idle typecheckery.
EDIT: Actually, I understand why this program should be rejected (comment:1), but the error message is surely misleading and should be fixed.