Zulip Chat Archive

Stream: new members

Topic: legal namespace usage


Quinn (Mar 22 2024 at 18:20):

namespace Real
  variable (T : Type)
end Real
#check Real.T

I can't get past "unknown identifier: Real.T".

Ruben Van de Velde (Mar 22 2024 at 18:31):

What do you think that would do? What are you trying to do?

Quinn (Mar 22 2024 at 18:43):

it seems like #check Real.T should just be Type

Quinn (Mar 22 2024 at 18:44):

cuz for the namespace's context that's what it is

Kevin Buzzard (Mar 22 2024 at 18:44):

Either the variable dies when you close the namespace or it stays being called T

Quinn (Mar 22 2024 at 18:48):

namespace Real
  variable (T : Type)
end Real
open Real
#check T

(also fails) i'm confused why i'm able to open a namespace without supplying values for the variables declared

Eric Wieser (Mar 22 2024 at 18:54):

namespaces are for declarations, not variables

Kyle Miller (Mar 22 2024 at 19:01):

If you're following Mathematics in Lean, this chapter mentions variable: https://leanprover-community.github.io/mathematics_in_lean/C02_Basics.html

Kyle Miller (Mar 22 2024 at 19:03):

It's for declaring parameters to definitions and theorems for the rest of the section. (They get removed from the definition or theorem if they are not used.) They are not definitions or theorems themselves.

Kyle Miller (Mar 22 2024 at 19:04):

If you want something in the Real namespace, you have to make definition or theorem.

namespace Real
def T := Type
end Real
#check Real.T
-- Real.T : Type 1

Quinn (Mar 22 2024 at 19:26):

great explanation thanks!

Mario Carneiro (Mar 22 2024 at 19:59):

Quinn said:

namespace Real
  variable (T : Type)
end Real
open Real
#check T

(also fails) i'm confused why i'm able to open a namespace without supplying values for the variables declared

It sounds like you are thinking of modules in the style of Coq or ML. Lean does not have a module system in this sense, so variable declarations have local effect only and theorems using them are generalized immediately after the definition, not at the end of the section. Once the section or namespace is closed or you go to a new file, the variable is completely gone and has no lasting effect.


Last updated: May 02 2025 at 03:31 UTC