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

lambda expression = something is really tripping me up #336

Open dotnetCarpenter opened 4 years ago

dotnetCarpenter commented 4 years ago

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 commented 4 years ago

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! :+1: