<div>Hi Cafe,<br></div><div><br></div><div>With this class definition with this instance:<br></div><div><br></div><div>    class C a where<br></div><div>    instance C b => C (a, b)<br></div><div><br></div><div>GHC can of course infer, given 'C b', that 'C (a, b)'. This is nothing more<br></div><div>than the meaning of the instance declaration above.<br></div><div><br></div><div>However, GHC cannot infer the inverse:<br></div><div><br></div><div>    {-# LANGUAGE FlexibleContexts #-}<br></div><div><br></div><div>    foo :: C a => a -> Int<br></div><div>    foo = undefined<br></div><div><br></div><div>    bar1 :: C (a, b) => a -> b -> Int<br></div><div>    bar1 _ = foo<br></div><div><br></div><div>This gives an error on the right-hand side of 'bar1': "Could not deduce (C b)<br></div><div>arising from a use of ‘foo’; from the context: C (a, b)". The same happens in<br></div><div>similar cases:<br></div><div><br></div><div>    {-# LANGUAGE GADTs #-}<br></div><div><br></div><div>    bar2 :: (C p, p ~ (a, b)) => a -> b -> Int<br></div><div>    bar2 _ = foo<br></div><div><br></div><div>    data Thing a where<br></div><div>        Tup :: a -> b -> Thing (a, b)<br></div><div><br></div><div>    bar3 :: C a => Thing a -> Int<br></div><div>    bar3 (Tup x y) = foo y<br></div><div><br></div><div>Both these usages of 'foo' yield the same error.<br></div><div><br></div><div>My use-case is 'bar3', where I would like GHC to determine that the call to<br></div><div>'foo' is valid. (I don't actually care directly about bar1 and bar2.)<br></div><div><br></div><div>Is there a way to make 'bar3' compile?<br></div><div><br></div><div>Note that:<br></div><div>- In my actual use case, 'C' is of course not empty.<br></div><div>- In my actual use case, my type class instances _are_ in fact injective, even<br></div><div>  though I do enable FlexibleInstances to be able to write e.g.<br></div><div>  'instance C (T a Int)'.<br></div><div>- Above, the dictionary for 'C (a, b)' includes a dictionary for 'C b', doesn't<br></div><div>  it? So if inference can resolve 'C b', then the compilation to Core can find<br></div><div>  the right dictionary, I think? (Not sure about this part.)<br></div><div><br></div><div>Thanks a lot for your help.<br></div><div><br></div><div>Cheers,<br></div><div>Tom<br></div><div><br></div>