File: lambda_case.rst

package info (click to toggle)
ghc 9.10.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 169,076 kB
  • sloc: haskell: 713,554; ansic: 84,184; cpp: 30,255; javascript: 9,003; sh: 7,870; fortran: 3,527; python: 3,228; asm: 2,523; makefile: 2,324; yacc: 1,570; lisp: 532; xml: 196; perl: 111; csh: 2
file content (49 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
.. _lambda-case:

Lambda-case
-----------

.. extension:: LambdaCase
    :shortdesc: Enable lambda-case expressions.

    :since: 7.6.1
    :status: Included in :extension:`GHC2024`

    Allow the use of lambda-case syntax.

The :extension:`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 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0302-cases.rst>`_)
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 :extension:`LambdaCase` with
:extension:`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