elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
173 stars 17 forks source link

unlear (?) error messages when working with tuples #327

Open benkoshy opened 4 years ago

benkoshy commented 4 years ago

https://package.elm-lang.org/packages/elm-lang/core/latest/Tuple

My perspective

The 1st argument to `second` is not what I expect:

653|         y = second getDimensions(difficulty)            
                        ^^^^^^^^^^^^^
This `getDimensions` value is a:

    Difficulty -> ( Int, Int )
-- getDimensions takes a dimension and returns a tuple

But `second` needs the 1st argument to be:

    ( a, b -> c )

-- but the error message is a little confusing.

I suspect the problem is that we are inputting a "difficulty" and returning a tuple, instead of straight away getting a tuple (without a function which takes a 'difficulty' parameter. The compiler message leaves me a little non-plussed.

My two cents.

benkoshy commented 4 years ago

I found out that the issue is was actually to do with the order of the brackets. This was the correct answer.

  y = second (getDimensions difficulty) 

The all important question to be answered: is the compiler message adequate, or is it just a programmer error/ignorance?

jjant commented 4 years ago

@BKSpurgeon The message is correct, albeit a bit unclear.

The reason you get this error is that your code is parsed like so:

y = (second getDimensions) difficulty

Thus it thinks that getDimensions should be a tuple (because you're calling second on it), and that its second element has to be a function (because you're calling that with difficulty).