6.2.13. Lambda-case — Glasgow Haskell Compiler 9.10.0.20240328 User's Guide

# 6.2.13. Lambda-case

`LambdaCase`

  Since: | 7.6.1
  Status: | Included in `GHC2024`

  Allow the use of lambda-case syntax.

The `LambdaCase` extension enables expressions of the form

    \case { p1 -> e1; ...; pN -> eN }

which is equivalent to

    \freshName -> case freshName of { p1 -> e1; ...; pN -> eN }

Since GHC 9.4.1, it also allows expressions with multiple scrutinees (see GHC proposal #302) of the form

    \cases { p11 ... pM1 -> e1; ...; p1N ... pMN -> eN }

which is equivalent to a function defined as

    f p11 ... pM1 = e1
    ...
    f p1N ... pMN = eN

Note that both `\case` and `\cases` start a layout, so you can write

    \case
      p1 -> e1
      ...
      pN -> eN

Additionally, since GHC 9.0.1, combining `LambdaCase` with `Arrows` allows `\case` (and since GHC 9.4.1 `\cases`) syntax to be used as a command in `proc` notation:

    proc x -> (f -< x) `catchA` \case
      p1 -> cmd1
      ...
      pN -> cmdN