Zulip Chat Archive
Stream: new members
Topic: How to create a hidden namespace?
Yee-Jian Tan (Oct 07 2025 at 16:04):
I have this simple MWE:
namespace hidden
notation:100 "ℕ" => Nat
axiom add : ℕ → ℕ → ℕ
variable (w x y z : ℕ)
#check add x y
local infixl:65 " + " => add
#check x + y
end hidden
the #check x+y returns
Ambiguous term
x + y
Possible interpretations:
x + y : ℕ
x + y : ℕ
Kenny Lau (Oct 07 2025 at 16:10):
why are you redefining an existing infix?
Yee-Jian Tan (Oct 07 2025 at 16:14):
I guess the question should be: how can I create a hidden namespace, or forget/hide existing notations?
Kenny Lau (Oct 07 2025 at 16:16):
I could be wrong, but I don't think there's a way to remove a globally-defined notation in the prelude
Kenny Lau (Oct 07 2025 at 16:16):
i would suggest you modify the symbol e.g. +'
Kenny Lau (Oct 07 2025 at 16:17):
also I think another part of your problem is that you're still using the Nat instead of a new nat
Kenny Lau (Oct 07 2025 at 16:17):
namespace hidden
axiom myNat : Type
notation:100 "ℕ" => myNat
axiom add : ℕ → ℕ → ℕ
variable (w x y z : ℕ)
#check add x y
local infixl:65 " + " => add
#check x + y
end hidden
Kenny Lau (Oct 07 2025 at 16:17):
for example this works
Yee-Jian Tan (Oct 07 2025 at 16:28):
That's good to know. Still, is there a way to use the same Nat and the same symbol + ?
Kenny Lau (Oct 07 2025 at 16:28):
I don't think so.
Alfredo Moreira-Rosa (Oct 07 2025 at 16:34):
In case you don't know you can write your own instances of HAdd or Add typeclasses and evoid the issue of defining your own infix, and it will respect your hidden namespace
Robin Arnez (Oct 07 2025 at 17:54):
The thing to do with existing notation is not to redefine it but to create macro_rules:
variable (x y : Nat)
section
axiom add (a b : Nat) : Nat
local macro_rules
| `($a + $b) => `(add $a $b)
@[app_unexpander add]
def unexpandAdd : Lean.PrettyPrinter.Unexpander
| `($_ $a $b) => `($a + $b)
| _ => throw ()
/-- info: x + y : Nat -/ #guard_msgs in
#check x + y
set_option pp.notation false in
/-- info: add x y : Nat -/ #guard_msgs in
#check x + y
end
/-- info: x + y : Nat -/ #guard_msgs in
#check x + y
set_option pp.notation false in
/-- info: HAdd.hAdd x y : Nat -/ #guard_msgs in
#check x + y
Robin Arnez (Oct 07 2025 at 18:02):
If you don't want to write the unexpander yourself or want more control over precedence etc., you can instead disable the existing notation:
local macro_rules
| `($a + $b) => Lean.Macro.throwError "macro disabled"
local infixl:65 " + " => add
Yee-Jian Tan (Oct 14 2025 at 12:51):
Thanks! For pedagogical purposes, I decided to stick with another symbol (i.e. suffixed with ') instead, it would have been nice if we could disable these natively.
Last updated: Dec 20 2025 at 21:32 UTC