What is a good way to notate pattern-matching expressions?

35 Views Asked by At

I would like to notate pattern matching like in various programming languages in normal math notation.

Have this expression in Haskell:

case x of
  Leaf -> 1
  (Node a b) -> 2

How could I transscribe that to normal mathematical notation so it is easy to understand and does not seem strange?

I could write that as a normal conditional, but that would repeat the $x$, which would be significant if the $x$ standed for a long expression: $$ \begin{cases} x = \mathrm{Leaf}: & 1 \\ x = \mathrm{Node}(a,b): & 2 \end{cases} $$

I could make my notation for pattern matching, but that could be hard to understand and my variant has too much text IMO: $$ \mathrm{match} \ x \ \begin{cases} \mathrm{Leaf}: & 1 \\ \mathrm{Node}(a,b): & 2 \end{cases} $$

These are supposed to be expressions so they can be used in larger expressions: $$ f(x) = 1 + \mathrm{match} \ x \ \begin{cases} \mathrm{Leaf}: & 1 \\ \mathrm{Node}(a,b): & 2 \end{cases} $$

Are there examples of such pattern matching in something already published, and what? I would like to see that so I can [not make my notation from scratch].