Zulip Chat Archive
Stream: new members
Topic: Exporting scoped notation between namespaces
Jad Ghalayini (Feb 05 2025 at 19:52):
Say I define a notation in some namespace, e.g.
namespace Hello
scoped infixl:81 " ⋉ " => bleh
end Hello
Is there an idiomatic way to re-export this to another namespace, e.g.
namespace Hello2
(somehow import ⋉)
end Hello2
such that there won't be a conflict if both namespaces are open?
Aaron Liu (Feb 05 2025 at 19:56):
Do you want something like open scoped Hello?
Jad Ghalayini (Feb 05 2025 at 19:58):
Will that work if I import Hello2?
Jad Ghalayini (Feb 05 2025 at 19:58):
What I'd like is to be able to do
open Hello2
(use ⋉ without knowing Hello exists)
Nick Ward (Feb 05 2025 at 20:01):
You could use scoped[Hello2] notation to put the notation into a namespace different from where it is defined.
Nick Ward (Feb 05 2025 at 20:02):
So if you did scoped[Shared] notation .. then both Hello and Hello2 could open scoped Shared.
Jad Ghalayini (Feb 05 2025 at 20:02):
Ah, let me try it...
Jad Ghalayini (Feb 05 2025 at 20:07):
Hmm... can we avoid that? I don't want to complicate the API, since most people will only ever use Hello2 (not Hello or Shared)?
Nick Ward (Feb 05 2025 at 20:09):
You could put it directly into Hello2 with scoped[Hello2] notation from Hello.
Nick Ward (Feb 05 2025 at 20:09):
(it's also possible re-exporting is a thing and I've just never stumbled across it).
Yaël Dillies (Feb 05 2025 at 20:11):
Do you know about export?
Jad Ghalayini (Feb 05 2025 at 20:16):
Yes, but that's for names right
Jad Ghalayini (Feb 05 2025 at 20:16):
Like
export PremonoidalCategory (ltimes rtimes Pentagon)
Jad Ghalayini (Feb 05 2025 at 20:16):
What I'm experimenting with is moving
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
to PremonoidalCategory and somehow re-exporting it
Nick Ward (Feb 05 2025 at 20:16):
I did not! Maybe the following would work?
namespace Foo
def add1 (n : ℕ) := n + 1
notation (name := note) "~" n "~" => add1 n
end Foo
namespace Bar
export Foo (note)
end Bar
Yaël Dillies (Feb 05 2025 at 20:20):
Yes, exactly, notations too have names, so I would hope they can be similarly exported (I have no clue whether they actually can)
Jad Ghalayini (Feb 05 2025 at 20:42):
Nope I get unknown constant 'CategoryTheory.MonoidalCategoryStruct.tensorObjNotation'
Jad Ghalayini (Feb 05 2025 at 20:43):
Sorry, had a typo, now I get invalid 'export', self export
Jad Ghalayini (Feb 05 2025 at 20:43):
No wait it works
Jad Ghalayini (Feb 05 2025 at 20:43):
I am very sleep deprived, ignore that
Nick Ward (Feb 05 2025 at 20:49):
Not sure if the above actually worked or not, but the better solution might be a "neutral" namespace, where you define all of the notation (whether in PremonoidalCategory or MonoidalCategory) as scoped[Monoidal] notation, then everyone just does open scoped Monoidal instead of open scoped MonoidalCategory.
Jad Ghalayini (Feb 05 2025 at 21:39):
So it works but then other things in other files broke in subtle ways, so I decided to just leave it for now
Last updated: May 02 2025 at 03:31 UTC