Can we improve type error messages?

I am sorry, but would you mind listening to what I have been explaining to you since the start of this strange discussion?

I can see that the name type-directed disambiguation might have induced you in error, but I assure you that the error is a type-directed constructor resolution error, not a type error mismatch error.

Since the introduction of type-directed constructor resolution, constructors (and fields) are not uniquely
associate to a type. And when a constructor resolution fails it doesn’t make sense to pick arbitrarily one non-matching type in order to fail in a familiar but unrelated way.

This is what happens today in OCaml typechecker. This is a fact, and not a point that you can discuss.

Rather than trying to fight the reality of OCaml type system to make it fit your perception, I believe that you would better spend your time and energy explaining what you find so confusing in the initial error message. Because, yes, my point of view is biased (after all I am one of the author of this error message), but I fail to see what is so problematic with

 Error: This variant expression is expected to have type
         ('a, unit, string, node) format4
    There is no constructor (::) within type format6

maybe corrected to

 Error: This variant expression is expected to have type
         ('a, unit, string, node) format4
    There is no constructor (::) within type format4 = format6
    Hint: List literal `[x;...] can also be read as `x:: ... `. 

Indeed, the error message is to the point, it indicates that we had an expected type and explicit variant constructor ::, and that the two cannot match.

  • it describes all the information that we have locally at the point of the conflict.
  • The error message is not making any possibly wrong assumption or ignoring one possible fix.
  • The error message is accessible and readable, even in a braille reader.

Even reading the initial report, I fail to see how your proposed correction would help.

because the core part of the error, that we expected a format string and got a mismatched constructor is already here.
We clearly ought to make clearer the connection with the list literals, maybe we can reword the mismatching constructor error message to make it clearer that we compared the present constructors with the one available in the expected type; but there is no reason to evoke the list type here.

Maybe we could reword the error message to:

 Error: This variant constructor `(::)` is expected to have type
         ('a, unit, string, node) format4
    There is no variant constructor (::) within type format4 = format6
    Hint: List literal `[x;...] can also be read as `x:: ... `.

or if the information about the sugared list literal syntax was available:

 Error: This list literal is expected to have type
         ('a, unit, string, node) format4
    There is no list constructor (::) within type format4 = format6