Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when attempting Haskell-style pattern matching #350

Open
Gaelan opened this issue Apr 4, 2021 · 1 comment
Open
Labels

Comments

@Gaelan
Copy link

Gaelan commented Apr 4, 2021

Quick Summary: When attempting to do Haskell-style pattern matching (multiple function declarations instead of one declaration with a case), the error message could be more helpful.

SSCCE

-- It's debatable whether this function is a good idea, but that's besides the point.
expect : String -> Maybe a -> a
expect _ (Just x) = x
expect msg Nothing = Debug.todo msg
This file has multiple `expect` declarations. One here:

3| expect msg Nothing = Debug.todo msg
   ^^^^^^
And another one here:

2| expect _ (Just x) = x
   ^^^^^^
How can I know which one you want? Rename one of them!

Additional Details

I learned Haskell before I learned Elm. Elm's similar enough that generally I can just write the same code I'd write in Haskell, and it works; when that's not the case, it's easy to get very confused (but you do know which one I want! they have distinct patterns!). Given that the mistake above is, I imagine, fairly common for (a certain type of) new Elm programmers, it'd be great if we got a more specific message, along the lines of "if you're trying to match on multiple patterns, use a single declaration and case" would be quite helpful.

@github-actions
Copy link

github-actions bot commented Apr 4, 2021

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

@evancz evancz transferred this issue from elm/compiler Jul 23, 2021
@evancz evancz added the parser label Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants