error-message-catalog icon indicating copy to clipboard operation
error-message-catalog copied to clipboard

Error message not helping when pattern matching `Set.empty` in case expression

Open digitalsatori opened this issue 6 years ago • 0 comments

The following code:

printUser users =
    case users of
        Set.empty ->
            text "Empty"
        _ ->
            text users

caused the syntax error below which is confusing:

-- SYNTAX PROBLEM --------------------------------------------------------------

I ran into something unexpected when parsing your code!

6|         Set.empty ->
               ^
I am looking for one of the following things:

    an upper case name

I will suggest @jessta 's answer to my question in the slack, which is much clearer and helpful:

The pattern in case..of need to be literals, they can't be functions or variables. Set.empty is a function.

You probably want to use a if..then..else and Set.isEmpty, eg. if Set.isEmpty users then text "empty" else text users

digitalsatori avatar Aug 02 '18 08:08 digitalsatori