Patterns vs guards
Remi Forax
forax at univ-mlv.fr
Mon Jan 18 08:03:10 UTC 2021
Hi everybody,
following the discussion about && / and between guards and patterns,
i don't think i've a clear understanding on what is a pattern and what is a guard.
When we first discuss of guards, the separation was a kind of clean, a pattern match something and a guard provides further refinements.
By example, with a made a syntax,
case Point(var x, var y) && x > 0 && y > 0
Point(var x, var y) is the pattern and x > 0 and y > 0 are the guards.
So a pattern asks if something match and a guard uses the binding to add restrictions.
As Brian said, in C#, you can directly test inside a pattern, using a weird syntax chosen by C# like >0,
so the same example can be rewritten
case Point(>0, >0)
and with the bindings, i suppose something like
case Point(var x >0, var y >0)
Here the line between a pattern and a guard starts to become blurry, because >0 is pattern.
So if there a difference between a pattern and a guard ?
regards,
Rémi
More information about the amber-spec-experts
mailing list