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

lambda expression = something is really tripping me up #336

Open
dotnetCarpenter opened this issue Apr 28, 2020 · 1 comment
Open

lambda expression = something is really tripping me up #336

dotnetCarpenter opened this issue Apr 28, 2020 · 1 comment

Comments

@dotnetCarpenter
Copy link

Lambda or anonymous function for String.filter or String.map always give me this weird error message.

Whatever I am running into is confusing me a lot! Normally I can give fairly
specific hints, but something is really tripping me up this time.

Detected problems in 1 module.
-- SYNTAX PROBLEM ------------------------------------------------- src/Main.elm

I got stuck here:

97|   || String.filter \c -> Char.isUpper c pw |> String.isEmpty
                       ^
Whatever I am running into is confusing me a lot! Normally I can give fairly
specific hints, but something is really tripping me up this time.

The surrounding code is the following:

-- False if pw is weak, True if it's strong
weakPassword : String -> Bool
weakPassword pw =
  test pw Char.isLower
  -- || test pw Char.isUpper
  || String.filter \c -> Char.isUpper c pw |> String.isEmpty
  || test pw Char.isDigit

-- True if predicate yields an empty string
test : String -> (Char -> Bool) -> Bool
test s predicate =
  String.filter predicate s |> String.isEmpty

It looks to me that

String.filter \c -> Char.isUpper c pw |> String.isEmpty

is the exact same as the body of the test function, if predicate is replaced with \c -> Char.isUpper c . I have tried to add parentheses around the lambda but that just give me other error messages.

String.filter predicate s |> String.isEmpty

I'm new, so it might not always be an error but I have only ever got an error message when I try.

Anyway, the reason for this issue is: Whatever I am running into is confusing me a lot! Normally I can give fairly specific hints, but something is really tripping me up this time.

@lydell
Copy link

lydell commented Apr 28, 2020

This is syntactically correct:

String.filter (\c -> Char.isUpper c) pw |> String.isEmpty

And it means the same thing as:

String.filter Char.isUpper pw |> String.isEmpty

Either way, that error message could be better! 👍

@dotnetCarpenter dotnetCarpenter changed the title lambda for .filter/.map is always an error lambda expression = something is really tripping me up Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants