Date: Fri, 23 May 2025 10:24:57 +0200
> On 20 May 2025, at 13:48, Jens Maurer via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> Have you reviewed the pending pattern matching proposal(s),
> such as https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2688r5.html ?
There is a powerful pattern matching construct in Haskell, with the syntax
case x of { p₀ → e₀; … }
For each pattern p₀, …, there must be a predicate telling when it is valid, and an invertible constructor, telling the values of any variables present.
For lists written [a₀, …], with [] the empty list, and a constructor a:as ≔ [a, as₀, …] with inverses first(a:as) = a, rest(a:as) = as, one can write (in layout syntax)
case x of
[] -> b
a:as -> c
which translates into something like (in C++ like pseudocode)
if empty(x) then return b() else
if ¬empty(x) then return c[a ↦ first(x)][as ↦ rest(x)]
where A[s ↦ e] denotes substitution.
This way, one can have patterns that contain variables.
>
> Have you reviewed the pending pattern matching proposal(s),
> such as https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2688r5.html ?
There is a powerful pattern matching construct in Haskell, with the syntax
case x of { p₀ → e₀; … }
For each pattern p₀, …, there must be a predicate telling when it is valid, and an invertible constructor, telling the values of any variables present.
For lists written [a₀, …], with [] the empty list, and a constructor a:as ≔ [a, as₀, …] with inverses first(a:as) = a, rest(a:as) = as, one can write (in layout syntax)
case x of
[] -> b
a:as -> c
which translates into something like (in C++ like pseudocode)
if empty(x) then return b() else
if ¬empty(x) then return c[a ↦ first(x)][as ↦ rest(x)]
where A[s ↦ e] denotes substitution.
This way, one can have patterns that contain variables.
Received on 2025-05-23 08:25:13