Misleading type error message with type families
This incorrect program
https://play.haskell.org/saved/wg3Qe6D8
fails with
Main.hs:16:7: error:
• Could not deduce (Num 42) arising from a use of ‘rnnMnistZeroR’
from the context: Ranked (Value r) 42 ~ Maybe (Value r)
bound by the type signature for:
foo :: forall r. (Ranked (Value r) 42 ~ Maybe (Value r)) => r
at Main.hs:15:1-49
while it should fail with "Could not deduce (Num (Value r))" and indeed tweaking or simplifying the program often yields the proper error.
The error message is wrong not only in that the proposed fix does not correct the example, but also the fix (Num 42
) is kind-incorrect in itself and GHC duly complains when it's attempted.
This happens to me a lot in wild when I work with such two-argument type families and makes debugging harder. This happens from GHC 8.6.5 to 9.6.1.