Is Dependent Type a subtype?

trait A {
  trait B {
    def foo: A.this.B = new B{}
    def bar: A#B      = foo 
    def baz: A.this.B = bar // type mismatch; found : A#B required: A.this.B 
  }
}

Is it right that a A.this.Bpath-dependent type ?! (This is my understanding so far) Does the above example mean that a type A.this.Bis a subtype A#B? (If yes, I think the difference is that the instance A.this.Bhas a reference to the instance Acompared to A#Bwhich is not?) Does anyone know an explanatory explanation that resolves my confusion with these two types?

+3
source share
3 answers

The excellent Scala Programming book has a pretty good explanation :

class Outer {
  class Inner
}

Scala Outer#Inner Java Outer.Inner. . . , , Outer, :

val o1 = new Outer
val o2 = new Outer

o1.Inner o2.Inner ( ). ( ) Outer#Inner, Inner Outer. , o1.Inner Inner ( o1). , o2.Inner Inner , ( o2).

Scala, Java, . , , . , , . - . ( ). - . , , o1.Inner, , :

scala> new o1.Inner
res1: o1.Inner = Outer$Inner@13727f

, , o1. , Outer#Inner - Outer, :

scala> new Outer#Inner
<console>:6: error: Outer is not a legal prefix for
  a constructor
       new Outer#Inner
                 ^
+14

: ,

, A#B, A (, , , ), .

+5

, , . , B A # B. , A # B, B A

+2

All Articles