类型选择,类型投影。 Scala 中的 S#T 是什么?需要基于 Scala 语言规范的解释

Type selection, type projection. What is S#T in Scala ? Scala Language Specification based explanation is needed

在 SLS 3.4 中写成:"The definition of a type projection S#T is the member binding dT of the type T in S"。

我已经阅读 SLS 3.4 10 遍了,但我仍然不明白 S#T 是什么以及这种类型有什么样的值。

S#T 是什么意思?

什么是会员绑定?

什么是基类型?

更具体地说:为什么 if

class A
{ 
   class B
}

那么 A#B 指的是内部 class B 的任何实例?

如何从 SLS 第 3.4 节中得出此声明?

我认为这就是答案所在,但 SLS 很难理解。

这个问题是这个问题的 spin-off :Overriding members having Path Dependent types in Scala. Explanation is needed in terms of Scala Language Specification .

了解 S#T 的真正含义是 pre-requisit 能够找到 Overriding members having Path Dependent types in Scala. Explanation is needed in terms of Scala Language Specification 的答案。

提问原因:

普通人很难阅读 SLS。带着这个问题,我试图帮助那些想对 SLS 有所了解的凡人(包括我自己)。

似乎没有任何地方详细解释 SLS,Scala 书籍对于普通人和 SLS 之间存在差距。带着这个问题,我试图在这个差距上架起一座狭窄的桥梁。

在奥德斯基的书中写道:

他写的地方:

Both of these types conform to (are subtypes of) the more general type Outer#Inner, which represents the Inner class with an arbi- trary outer object of type Outer.

最后一题:

问题是,SLS 如何证明这种说法?

这个语句怎么可能是来自 SLS 的 "derived"?

为了能够回答最后一个问题,必须了解 S#T 的真正含义。

我对 A#B 没有法律上的理解(只有实际的理解)所以我无法帮助第一部分,但我可以回答你的最后一个问题:根据 3.2.3,类型 o1.Innero1.type#Inner。根据 3.5.2,"A type projection T#t conforms to U#t if T conforms to U"。希望 o1.type <: Outer 很明显;严格来说这是因为(再次在 3.5.2 中)"A singleton type p.type conforms to the type of the path p".