0
比方說,我有一個包裝類類型推斷不一致
case class Cont [E] (e : Seq[E]) {
def :: [E1 >: E] (e1 : Seq[E1]) : Cont[E1] = Cont(e1 ++ e)
def + [E1 >: E] (e1 : Seq[E1]) : Cont[E1] = Cont(e1 ++ e)
}
而是對某種類型的序列的包裝。它可以接受另一種類型的序列,並返回新的包裝,用於附加序列現在使用它們超類型的類型。它有兩種方法 - 從右到左用::和從左到右用+。
現在這些鏈接的結果是:
Cont(Seq[Nothing]()) //-> Cont[Nothing]
Seq[Nothing]() :: Cont(Seq[Nothing]()) //-> Cont[Nothing]
Seq[Nothing]() :: Seq[Nothing]() :: Cont(Seq[Nothing]()) //-> Cont[E1]
Seq[Int]() :: Seq[Nothing]() :: Seq[Nothing]() :: Cont(Seq[Nothing]()) //-> Cont[Any]
Cont(Seq[Nothing]())//-> Cont[Nothing]
Cont(Seq[Nothing]()) + Seq[Nothing]()//-> Cont[Nothing]
Cont(Seq[Nothing]()) + Seq[Nothing]() + Seq[Nothing]() //-> Cont[Nothing]
Cont(Seq[Nothing]()) + Seq[Nothing]() + Seq[Nothing]() + Seq[Int]() //-> Cont[Int]
結果應該是相同的或不應該他們?他們不是。我需要第二個(從左到右)的行爲。我甚至不知道Cont [E1]是什麼意思。這有什麼原因?有沒有修復代碼使用::?
這似乎是一個錯誤 - 「繼續[E1]」不是有效的類型。此外,對於第三種情況,「Cont [Nothing]」已足夠,對於第四種情況,「Cont [Int]」已足夠。 – sschaef