Uninformative error message for unknown type variables
Currently, in error messages reporting that a particular constraint cannot be solved for some reason, the full types in which the relevant type variables occur are not printed.
See for example this case by @phadej: https://gist.github.com/phadej/7b95d1876dd085d28f49bf4ebf349663. Which literal is the problem,
Alternatively, consider the following case: (arising from a large snippet of code written using
accelerate, where writing type signatures for all auxiliary bindings is tedious and introduces noise)
data Exp a class Elt a map' :: (Elt a, Elt b) => Exp a -> Exp b -> () map' = undefined constant' :: Elt a => a -> Exp a constant' = undefined a40f f = map' (f (constant' 2.0)) (f (constant' 3.0)) a40 = a40f id
This gives the error message:
test.hs:11:7: error: • No instance for (Elt b0) arising from a use of ‘a40f’ • In the expression: a40f id In an equation for ‘a40’: a40 = a40f id | 11 | a40 = a40f id |
While in this case it is fairly clear what the problem is, the error message is uninformative: what is
b0 and where does it come from? Although we know any
Elt constraints here will come from
constant', we still don't know whether it's the first or the second argument to
map'. Consider also that
constant' may be from a library.
Sometimes a "relevant binding" is displayed with a type that contains the concerned type variable(s), giving very useful information about the situation, but often (as here) this is not the case.
For errors of the form
... arising from a use of ‘myFunction’, I would like to see the type of
myFunction, which presumably contains the type variables that GHC is complaining about (via e.g. some uninferrable context).
In particular, I'd like this for the errors
Ambiguous type variable ‘x10’ arising from a use of ‘a40f’ prevents the constraint ‘(Elt x10)’ from being solved. and
No instance for (MyIntegral b1) arising from a use of ‘plus2’.