In 0.19 I often got an error message of the form “this call produces a x
, but the type annotation says it should be a y
” where x
and y
were in fact identical!
I eventually worked out that the simplest way this was happening was when I accidentally provided a function instead of the result of that function as an argument to something, when the answer itself still needed to be a function. Probably an example explains this better. Under 0.19, the following:
makeTranslator : String -> String -> String
makeTranslator =
Debug.todo ""
translator : String -> String
translator =
makeTranslator
produces the error:
Something is off with the body of the
translator
definition:11| makeTranslator
^^^^^^^^^^^^^^
ThismakeTranslator
value is a:String → String
But the type annotation on
translator
says it should be:String → String
I can confirm that under 0.19.1 I now get a correct error message, namely:
Something is off with the body of the
translator
definition:11| makeTranslator
^^^^^^^^^^^^^^
ThismakeTranslator
value is a:String → String → String
But the type annotation on
translator
says it should be:
String → String
Hint: It looks like it takes too many arguments. I see 1 extra.
However, when this error is triggered in more complicated code, the provided hint isn’t always appropriate. Consider the following example, which is a reduction of a real world error I encountered when trying to understand Url.Parser
…
type Parser x y
= Parser x y
string : Parser (String -> a) a
string =
Debug.todo ""
slash : Parser a b -> Parser b c -> Parser a c
slash =
Debug.todo ""
test : Parser (String -> String) String
test =
slash string string
Under 0.19 this again produced an incorrect error message of:
Something is off with the body of the
test
definition:20| slash string string
^^^^^^^^^^^^^^^^^^^
Thisslash
call produces:Parser (String → String) String
But the type annotation on
test
says it should be:Parser (String → String) String
Under 0.19.1 the error message (below) is improved again, however the hint is (in my opinion) now very confusing for someone trying to understand what is going wrong (what takes too many arguments?)…
Something is off with the body of the
test
definition:20| slash string string
^^^^^^^^^^^^^^^^^^^
Thisslash
call produces:Parser (String → String → String) String
But the type annotation on
test
says it should be:Parser (String → String) String
Hint: It looks like it takes too many arguments. I see 1 extra.
But that’s just my opinion, possibly others don’t think it so confusing. The error message is still vastly improved over 0.19!