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

Missing argument reported as problem with different function #275

Open rtfeldman opened 5 years ago

rtfeldman commented 5 years ago

I forgot to pass a [] as the second argument to an input element. Here's the error:

-- TYPE MISMATCH -------------------------------------------- src/Page/Login.elm

The 2nd argument to `fieldset` is not what I expect:

123|         [ fieldset [ class "form-group" ]
124|>            [ input
125|>                [ class "form-control form-control-lg"
126|>                , placeholder "Email"
127|>                , onInput EnteredEmail
128|>                , value form.email
129|>                ]
130|>            ]

This argument is a list of type:

    List (List (Html Msg) -> Html Msg)

But `fieldset` needs the 2nd argument to be:

    List (Html msg)

Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!

The root problem is that the input function is missing an argument, but input is not mentioned in the error message.

Personally I've seen variations of this error enough times to mentally translate "got A -> B but needed something more like B" into "check if you forgot an argument somewhere" so this was enough for me to spot the problem.

I wanted to report this because I often see beginners trip over errors like this when I'm teaching Intro to Elm workshops. For the most part they praise how helpful Elm's compiler errors are, but whenever they call me over to ask what a particular TYPE MISMATCH is trying to tell them, the most common answer is "you're missing an argument somewhere."

I have a suspicion that this could be one of those "beginners don't complain about it so much as conclude they're not smart enough and give up" errors.