Not for every case

Even with all its goodness, there are still situations where a case expression will not work, and you will need to use different pattern.

No constants in case.

You can use literals, including Union Typed variables, in case expressions. But you cannot use constants.

-- THIS WORKS

case language of

"Spanish" ->

...



-- THIS DOES NOT WORK

localLanguage = "Spanish" case language of

localLanguage ->

...

The second one does not work because elm uses the localLanguage in the branch as a pattern matcher: if language matches the general pattern that it is a “thing that could be anything” (basically always), it will assign the value of that part inside language (in this case the whole language) to the new variable localLanguage .

For constructed types we use this all the time in branches like Just user -> to do something with the user inside a Maybe , or in the pattern a::b::rest in the earlier example.

Elm always uses lower case variables in case branches for pattern matching, and only allows literals. Elm does not allow case expressions on constants or assigned values. Probably this has to do the guarantees on the compiler needs to make that your branches cover all possible cases.

No pattern matching on record contents.

In case expressions, you can use literals inside strong types (using its type constructor), but I have not yet found a way to use the literals on record type constructor.

-- THIS WORKS

type Locale = Locale String String



case someLocale of

Locale "es" "es" ->

...



-- THIS DOES NOT WORK

type alias Locale = { language : String, country : String }



case someLocale of

Locale "es" "es" ->

...