Note [Unify with expected type before typechecking arguments]
Consider this (#19364) data Pair a b = Pair a b baz :: MkPair Int Bool baz = MkPair "yes" "no" We instantiate MkPair with `alpha`, `beta`, and push its argument types (`alpha` and `beta`) into the arguments ("yes" and "no"). But if we first unify the result type (Pair alpha beta) with the expected type (Pair Int Bool) we will push the much more informative types `Int` and `Bool` into the arguments. This makes a difference: Unify result type /after/ typechecking the args • Couldn't match type ‘[Char]’ with ‘Bool’ Expected type: Pair Foo Bar Actual type: Pair [Char] [Char] • In the expression: Pair "yes" "no" Unify result type /before/ typechecking the args • Couldn't match type ‘[Char]’ with ‘Bool’ Expected: Foo Actual: String • In the first argument of ‘Pair’, namely ‘"yes"’ The latter is much better. That is why we call checkResultType before tcValArgs.
References 0
This Note does not link to any other.
Referenced by 4
- tcApp: typechecking applications GHC.Tc.Gen.App ×2
- GHC.Tc.Gen.App call site ×2