Zulip Chat Archive

Stream: lean4

Topic: Dot notation and iterated namespaces


Michael Stoll (Dec 31 2024 at 23:43):

Is the following a bug?

def A.B.C (n : Nat) : Nat := 37 + n

def A (α : Type) : Type := α  Nat

/- invalid field 'B', the environment does not contain 'A.B' -/
example (x : A Nat) : x.B.C 0 = 37 := rfl

(I noticed this when trying to write I.Quotient.mk with I : Ideal R, which gives an error even though Ideal.Quotient.mk exists.)

Matt Diamond (Jan 01 2025 at 00:24):

I think this would be a better example, since dot notation doesn't work unless the function has an argument with the root type:

def A (α : Type) : Type := α  Nat

def A.B.C (_ : A Nat) (n : Nat) : Nat := 37 + n

/- invalid field 'B', the environment does not contain 'A.B' -/
example (x : A Nat) : x.B.C 0 = 37 := rfl

My understanding of dot notation is that A.B.C is interpreted as (A.B).C and not A.(B.C), in which case your example is not a bug, but I don't know if that's the actual expected behavior.

Michael Stoll (Jan 01 2025 at 10:08):

Matt Diamond said:

I think this would be a better example, since dot notation doesn't work unless the function has an argument with the root type:

True (I may have had a bit too much prosecco yesterday night :smile:). But your example (and docs#Ideal.Quotient.mk as well) shows that there really is an issue.

Michael Stoll (Jan 01 2025 at 13:11):

Unfortunately, x.(B.C) doesn't parse...

Michael Stoll (Jan 01 2025 at 13:12):

Is there any possible ambiguity in (x.B).C versus x.(B.C)? Perhaps the parser could try the latter when the former does not make sense?

Junyan Xu (Jan 01 2025 at 13:55):

In Lean 3 it's possible to write ^.quotient.mk. Would be nice if the same works in Lean 4. Maybe open an issue (if there isn't already one)?

Michael Stoll (Jan 01 2025 at 14:38):

lean4#6491


Last updated: May 02 2025 at 03:31 UTC