Zulip Chat Archive
Stream: new members
Topic: Variables, and picking typeclass instances
Philippe Duchon (Jun 25 2025 at 14:51):
The recent discussion on variables made me think of this question.
Say I want to work with a specific instance of a typeclass. How do I make this clear to Lean?
Say, for instance, I want to work with formal power series: I have some ring R of coefficients, but I want the discrete topology on it so I can use the product topology. If I just write variable {R: Type*} [TopologicalSpace R], Lean will expect, based on what my concrete R is (probably the rationals, or the reals, or the complexes; with the integers, default typeclass synthesis would probably pick the one I want), to infer a topology on this, but this won't be the one I had in mind - and neither will the product topology on power series.
So, in a sense, I would like to say, "in this section, if you ever need a TopologicalSpace R, this is the one I have in mind". Now that I rephrase it this way, this is probably a very dumb question...
Aaron Liu (Jun 25 2025 at 14:52):
Do you want variable {R : Type*} [TopologicalSpace R] [DiscreteTopology R]?
Aaron Liu (Jun 25 2025 at 14:53):
Or do you want a type synonym to equip a type with the discrete topology
Kevin Buzzard (Jun 25 2025 at 16:09):
You might find that power series rings have got an optional topology which you can "switch on" which doesn't ask for a topology on R at all, but puts the maximal-ideal-adic topology on the power series ring.
Philippe Duchon (Jun 25 2025 at 16:59):
The topology example was just one that seemed to fit the question (a case where the exact wanted instance of a typeclass might reasonably depend on the situation); my question was more general in spirit.
Kevin Buzzard (Jun 25 2025 at 17:39):
The general solutions are type synonyms and prop-valued classes such as [Discrete topology R] or [IsModuleTopology R]
Kevin Buzzard (Jun 25 2025 at 17:40):
Similarly in measure theory there is [BorelSpace X] to say 'this arbitrary sigma algebra you just attached to this topological space is the Borel sigma algebra"
Last updated: Dec 20 2025 at 21:32 UTC