Can we improve somewhat on FS0001 errors of the form "The type X does not match the type Y" #3973
Labels
Area-Diagnostics
mistakes and possible improvements to diagnostics
Feature Improvement
Theme-Simple-F#
A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone
I would like to discuss improving the errors where an expected type is not equal to a given type. My problem with such errors is, they are virtually impossible to read or understand, even after years of programming experience, unless for the most trivial of cases.
For instance, just now I hit this:
Does this mean that
Result.create
cannot understanda -> string
as first argument, or does it mean that the type in the list is not supposed to be of typea -> string
but should be of typestring
? Or does it mean that the part before|>
results somehow in aXResult<string>
and this is not a proper type forResult.create
which expectsResult<('a -> string), 'b>
?It's not that it is impossible to find out, but I think the main problem is what we call in linguistics: interchangeable object/subject in a sentence, so that you cannot be certain what the message is talking about. It says apples are not equal to pears, but we know that, it doesn't add anything.
Suggestions
I could think of several ways of improving the error. I am not sure what kind of context information is available in the F# compiler, but here are some ideas:
I'm sure some variant can be concocted that is at least somewhat clearer than "the type X does not match the type Y", because that is just as telling as saying "42 does not equal 24": it doesn't explain anything, basically.
The text was updated successfully, but these errors were encountered: