11

Wie würde ich konvertieren:Scala rekursiv beschränkten Typ Parameter (F-begrenzt) Umwandlung geben Mitglied

trait Foo[A <: Foo[A]] 

ein Typ-Mitglied?

Das heißt, möchte ich etwas entlang der Linien der folgenden Möglichkeiten:

trait Foo { 
    type A <: Foo {type A = ???} 
} 

aber Ich habe Schwierigkeiten, weil der Name A bereits in der Art Verfeinerung genommen wird. Diese Frage ist ähnlich (und brachte aus): F-bounded quantification through type member instead of type parameter?

Antwort

16

einen Selbst-Typ:

scala> trait Foo { self => type A <: Foo {type A = self.A}} 
defined trait Foo 

scala> class Bar extends Foo { type A = Bar } 
defined class Bar 

scala> class Bar extends Foo { type A = Int } 
<console>:10: error: overriding type A in trait Foo with bounds <: Foo{type A = Bar.this.A}; 
type A has incompatible type 
     class Bar extends Foo { type A = Int } 
            ^
+0

Das war meine ursprüngliche Intuition, große Antwort! –