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