Note that in the definition
h :: c -> a -> b hca = g $ fa
there is no limit to the fact that f and g refer to the same instance that you define h for. (And this flexibility is often useful for specifying instances.)
From type inference, the result of g limited to the same type of b , and the argument f limited to type a , but nothing is said that T abc passed from one to the other uses the same c !
To fix this in this case, you can enable ScopedTypeVariables and do
hca = g (fa :: T abc)
Note that this works because data families are “injective” (arguments to the data family type can be inferred from the final type). If you used a type family, even that would not work, since then T abc would not necessarily define c at all.
source share