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

Using `Maybe` instead of `Just` #340

Open danfishgold opened 3 years ago

danfishgold commented 3 years ago

Something that I've seen a couple of times with beginners is writing Maybe 123 instead of Just 123. Currently (0.19.1) when you write that in the repl (or when you use Maybe outside of type definitions), this is the error you get:

> Maybe 123
-- NAMING ERROR ----------------------------------------------------------- REPL

I cannot find a `Maybe` variant:

3|   Maybe 123
     ^^^^^
These names seem close though:

    False
    True
    Maybe.Just
    EQ

Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.

This could be a great opportunity to mention the difference between Maybe and Just (and more generally the difference between type variables and associated data)

lawsdontapplytopigs commented 3 years ago

I agree. Coming from a more loosely typed language, it was difficult for me to wrap my head around what is the constructor, and what is the type. I suggest giving an example of how a Bool would be defined with an algebraic type system like Elm has, since everybody knows what a boolean is, regardless of programming background, and showing that you construct it with one of either True or False. Then, showing beginners how similar a Bool and a Maybe are may help them grasp the concept more easily.