Consider the following Haskell code:
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances,
FunctionalDependencies #-}
class C a b c | a b -> c
instance C (l (i,j)) (r i j) j
instance C (l i j) (r (i,j)) j
-- Conflict between the following two lines
instance C (l (i,j)) (r (i,j)) j
instance C (l i j) (r i j) j
Here, GHC yields a functional dependencies error between the last two lines. If I drop any of the last two instance declarations, the code compiles. I tried an analogue using type families, which also produced a conflict. My first question is: Why do the last two lines conflict, while the other declarations all work fine together?
In addition, if I change the very last line to
instance C (l i j) (r i j) i
GHC accepts the code. This seems quite weird, since the only thing that changes is the dependent type variable c. Can somebody explain this behavior?