我試圖使用Scala 2.10.0-M1如下:類型等效問題
def bar[C <: Container](c: C)(x: C#X): c.X = x
:使用這種形式時
trait Container {
type X
}
class Test[C <: Container](val c: C) {
def foo(x: c.X): C#X = x // this compiles fine
def bar(x: C#X): c.X = x // this does not compile
}
的問題是相同的
我真的不明白爲什麼foo
編譯,而bar
沒有。
我認爲c.X
和C#X
這裏應該是一樣的。
另外,我不明白的錯誤消息:
[error] found : x.type (with underlying type C#X)
[error] required: Test.this.c.X
[error] possible cause: missing arguments for method or constructor
[error] def bar(x: C#X): c.X = x // this does not compile
任何想法?
這是一個通常是一個設計問題,我想從路徑依賴類型中檢索類型。我爲此創建了[另一個問題](http://stackoverflow.com/questions/9065343/exposing-a-path-dependent-type-coming-from-a-singleton-type)。 – betehess 2012-01-30 14:29:18