Zulip Chat Archive

Stream: general

Topic: alias ignores private


Yaël Dillies (Sep 16 2022 at 18:54):

I wasn't expecting the following #checks to work.

import tactic.alias

section

private alias nat.add_le_add_iff_right  foo bar
private alias nat.lt_of_add_lt_add_left  baz

end

#check foo -- foo : ?M_2 + ?M_1 ≤ ?M_3 + ?M_1 → ?M_2 ≤ ?M_3
#check bar -- bar : ?M_2 ≤ ?M_3 → ?M_2 + ?M_1 ≤ ?M_3 + ?M_1
#check baz -- baz : ?M_1 + ?M_2 < ?M_1 + ?M_3 → ?M_2 < ?M_3

Yaël Dillies (Sep 16 2022 at 18:55):

I am willing to fix this myself, but I don't know how private works. Is it an attribute? Can alias detect it has been tagged?

Yaël Dillies (Sep 16 2022 at 18:55):

Context is #16141

Mario Carneiro (Sep 16 2022 at 18:57):

It's passed along to the command in the decl_meta_info. User commands can choose to not take that argument, in which case they don't support any modifiers (private, protected, noncomputable, @[attr] and /-- doc comment -/ are all in there)

Mario Carneiro (Sep 16 2022 at 18:57):

but if they do take the argument then they can potentially have any of those and can do what they want with it

Yaël Dillies (Sep 16 2022 at 18:57):

Ah so alias takes it and ignores it?

Mario Carneiro (Sep 16 2022 at 18:58):

then again, the capabilities of lean 3 meta code to apply this information to other commands is limited

Mario Carneiro (Sep 16 2022 at 19:05):

yeah, it doesn't seem like there is any way to do the equivalent of creating a private def from meta code. I'm going to say this is out of scope for the lean 3 version (it's already been ported to lean 4 so you can do it there). It wouldn't be too hard to check the decl_meta_info and give an error if you put weird modifiers on the declaration though

Yaël Dillies (Sep 16 2022 at 19:07):

Does alias actually do anything with any attribute? If not, we could remove its decl_meta_info altogether

Mario Carneiro (Sep 16 2022 at 19:07):

it uses the doc string

Yaël Dillies (Sep 16 2022 at 19:08):

Hmm, doesn't it autogenerate the docstring, actually?

Mario Carneiro (Sep 16 2022 at 19:08):

yes, unless you put a doc string on the alias command

Kyle Miller (Sep 16 2022 at 19:16):

Lean 3 core usually throws errors when there are unexpected modifiers. (Sometimes this leads to usability bugs, for instance you used to be able to write /-- foo -/ @[class] noncomputable local infix ` + ` := nat.add even though the infix command only looked at local.)

Kyle Miller (Sep 16 2022 at 19:17):

If it doesn't already exist, it might be good to have a standard function to call to check that certain modifiers are not set and report a standard error message if they are. For example, here's one source in the C++.


Last updated: Dec 20 2023 at 11:08 UTC