Zulip Chat Archive

Stream: general

Topic: protected as attribute


Johan Commelin (May 13 2020 at 11:07):

I think it has been discussed, but before the community fork: can we make protected an attribute? And if so, how hard would it be? (Maybe we can still support the current syntax of protected lemma ...?)

Gabriel Ebner (May 13 2020 at 11:14):

Can you elaborate on what the advantages of @[protected] would be?

Johan Commelin (May 13 2020 at 11:22):

@Gabriel Ebner One example would be: copy init.algebra.ring, replace all alphas by int, and mark all the proven lemmas as protected at the end. This way you don't have to replace every occurence of add_comm by int.add_comm, etc...

Johan Commelin (May 13 2020 at 11:22):

Better example: we have topological_space.is_open and _root_.is_open. Currently, if you open topological_space, this leads to conflicts.

Johan Commelin (May 13 2020 at 11:23):

Really, we would want to mark topological_space.is_open as protected after creating the class.

Gabriel Ebner (May 13 2020 at 11:24):

Oh, and also local attribute [protected] I guess.

Rob Lewis (May 13 2020 at 11:26):

It's not an attribute, but there's environment.mk_protected right now, so you can do this with a command. Can't remove it though.

Johan Commelin (May 13 2020 at 11:33):

Aha, maybe that's good enough for now.

Reid Barton (May 13 2020 at 12:00):

I don't think you can remove an attribute either. (Would you really want to make something protected locally? There's also open hiding.)

Johan Commelin (May 13 2020 at 12:08):

What does open hiding do? Does it locally unprotect things?

Johan Commelin (May 13 2020 at 12:09):

Because I might want to locally unprotect things

Rob Lewis (May 13 2020 at 12:09):

Hmm, the doc string for user_attribute says something about attributes being unremovable if you give an after_set without a before_unset. I thought this had to do with when you could use local attribute, but apparently not.

Reid Barton (May 13 2020 at 12:10):

No, it locally protects things (I think?)

Reid Barton (May 13 2020 at 12:10):

Locally unprotecting would be more like open showing (which doesn't exist)

Reid Barton (May 13 2020 at 12:10):

"Even though the person who wrote the library says I don't want to automatically import these names to top-level, I want to do it anyways"

Reid Barton (May 13 2020 at 12:11):

With an attribute you couldn't locally unprotect things anyways, could you?

Johan Commelin (May 13 2020 at 12:16):

Yeah, I see now

Sebastian Ullrich (May 13 2020 at 12:25):

Why, would local attribute [-protected] not work?

Reid Barton (May 13 2020 at 12:26):

Oh, I was under the impression that syntax doesn't exist or doesn't actually do anything or something like that.

Sebastian Ullrich (May 13 2020 at 13:00):

It doesn't work for all attributes, but there's no reason it shouldn't for a [protected] attribute

Johan Commelin (May 16 2020 at 09:14):

What should I do to make lean happy?

run_cmd environment.mk_protected int.neg_mul_eq_mul_neg
/-
basic.lean:47:0: error
don't know how to synthesize placeholder
context:
⊢ Type
basic.lean:47:8: error
type mismatch at application
  environment.mk_protected int.neg_mul_eq_mul_neg
term
  int.neg_mul_eq_mul_neg
has type
  ∀ (a b : ℤ), -(a * b) = a * -b : Prop
but is expected to have type
  environment : Type
Additional information:
/home/jmc/data/math/mathlib/src/init_/data/int/basic.lean:47:8: context: switched to simple application elaboration procedure because failed to use expected type to elaborate it, error message
  type mismatch, term
    ?m_1.mk_protected
  has type
    name → environment
  but is expected to have type
    tactic ?m_1
-/

Mario Carneiro (May 16 2020 at 09:16):

run_cmd do env  tactic.get_env,
  tactic.set_env $ env.mk_protected ``int.neg_mul_eq_mul_neg

Johan Commelin (May 16 2020 at 09:17):

Thanks! And when I want to do this for a whole list of names?

Johan Commelin (May 16 2020 at 09:17):

I'll need some fold, I guess?

Mario Carneiro (May 16 2020 at 09:18):

run_cmd do env  tactic.get_env,
  tactic.set_env $ [``nat, ``int].foldl environment.mk_protected env

Johan Commelin (May 16 2020 at 09:20):

Thanks again!


Last updated: Dec 20 2023 at 11:08 UTC