On Sat, Jan 24, 2026, at 12:25 PM, Tim Düsterhus wrote:
> Hi
>
> Am 2026-01-23 20:48, schrieb Larry Garfield:
>> The idea of the second being that, if you want just an identity match,
>> you can skip adding `is` on just that one arm.
>
> I don't understand what that is trying to say.
With a per-arm keyword, one could do this:
$result = match ($somevar) {
is Foo => 'foo', // This matches against the pattern `Foo`, which is a
class name.
Bar => 'bar', // This matches === against the constant `Bar`, whose
value is whatever.
};
The main reason we cannot just auto-detect whether it's a pattern is the
confusion between a class name and constant, since a constant is a legal
literal value for an identity match. With per-arm, you can opt-in to pattern
matching individually, at the cost of having to remember to repeat the keyword
on every line. With per-block, you only have to add the keyword once at the
cost of not being able to selectively use patterns or identity matching.
Which tradeoff is better is the option question. (Ilija and I disagree on
which to go with.) Or, if someone can suggest a way to allow automatic
detection reliably, that would also be most welcome. :-)
--Larry Garfield