Zulip Chat Archive

Stream: lean4

Topic: Mul match_pattern


Marcus Rossel (Apr 01 2024 at 17:41):

Why does the following work for Add but not Mul?

inductive E
  | add : E  E  E
  | mul : E  E  E

instance : Add E where
  add := .add

instance : Mul E where
  mul := .mul

def f : E  E
  | a + b => a
  | a * b => a -- invalid pattern, constructor or constant marked with '[match_pattern]' expected

Eric Wieser (Apr 01 2024 at 18:26):

I think it's there for Add to support n + 1 in matches

Eric Wieser (Apr 01 2024 at 18:27):

... and it has to be opted into explicitly, which I guess has not been done for Mul

Marcus Rossel (Apr 01 2024 at 19:12):

Eric Wieser said:

... and it has to be opted into explicitly, which I guess has not been done for Mul

Can I somehow opt in myself?

François G. Dorais (Apr 01 2024 at 20:27):

Attribute @[match_pattern]

Kyle Miller (Apr 01 2024 at 20:31):

Unfortunately it's a TagAttribute, so you can't add it from another module

Marcus Rossel (Apr 02 2024 at 09:34):

Kyle Miller said:

Unfortunately it's a TagAttribute, so you can't add it from another module

Too bad. Do you happen to know if this is just a temporary limitation, or is there a good reason for this?

Kim Morrison (Apr 02 2024 at 09:54):

This is for efficiency reasons. TagAttribute won't change in the near future.

Mario Carneiro (Apr 02 2024 at 11:33):

the usage of it for particular attributes might though

Mario Carneiro (Apr 02 2024 at 11:35):

although it seems like that approach is just going to lead to questions like "and why should we allow you to monkey patch our design decisions in this way?"

Mario Carneiro (Apr 02 2024 at 11:35):

at which point you may as well just propose the specific attribute you want placed upstream


Last updated: May 02 2025 at 03:31 UTC