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

Allow underscore patterns to be named. #111

Closed
allanderek opened this issue Aug 19, 2022 · 1 comment
Closed

Allow underscore patterns to be named. #111

allanderek opened this issue Aug 19, 2022 · 1 comment
Labels
accepted The issue has been reviewed and accepted for implementation good first issue Good for newcomers help wanted Extra attention is needed language proposal proposal of a major feature to the language

Comments

@allanderek
Copy link
Contributor

As we know, _ is used to mean ignore this value in a pattern, sometimes in a case expression, sometimes as one of the arguments to a function.

Haskell, and I think a few others, allow you to spell this as _ followed by any valid unqualified identifier.

This allows something like the following:

sumDict : Dict comparable Int -> Int
sumDict =
    Dict.foldl (\_key value -> total = value + total) 

or

sumDict : Dict comparable Int -> Int
sumDict =
    let
          add : comparable Int -> Int -> Int
          add _key value total =
               value + total
    in
    Dict.foldl add

I've always personally quite liked this. I like that it says something like "I'm ignoring the key here", as opposed to "I'm ignoring something".

One possible downside is that such names can become misleading after the thing that is matched is changed.

@robinheghan robinheghan added accepted The issue has been reviewed and accepted for implementation good first issue Good for newcomers labels Aug 20, 2022
@robinheghan robinheghan added this to the 0.2.0 - Hello, NodeJS milestone Aug 20, 2022
@robinheghan robinheghan added the language proposal proposal of a major feature to the language label Aug 20, 2022
allanderek added a commit to allanderek/compiler that referenced this issue Sep 1, 2022
…me after, whih is intended to allow documentation of the value that is being ignored: gren-lang#111
@robinheghan robinheghan added the help wanted Extra attention is needed label Sep 2, 2022
@robinheghan
Copy link
Contributor

Solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue has been reviewed and accepted for implementation good first issue Good for newcomers help wanted Extra attention is needed language proposal proposal of a major feature to the language
Projects
None yet
Development

No branches or pull requests

2 participants