Covariant type FParam occurs in contravariant position in type Seq[FParam] of value guesses
Consider this simple example:
1 2 3 4 5 6 |
它不会编译,因为
Covariant type
FParam occurs in contravariant position in typeSeq[FParam] of value guesses.
但SEQ是以
Conversely,consider this simple example with
ZZU1BLCK1/
同样的矛盾:在
我可以通过惊吓变异来确定这个问题,如描述在下一类边界,但为什么需要这样做是不可理解的。
1 2 3 4 5 6 7 8 |
问题1:
1 |
或者像SeqViewLike。
那么,为什么
1 2 3 4 5 6 7 8 | trait Animal case class Dog() extends Animal case class Cat() extends Animal val o = new Optimizer2[Dog, Any] val f: Dog => Any = (d: Dog) => ... o.optimize(f, List(Dog(), Cat())) // if we don't bind B in `guesses` for supertype of `FParam`, it will fail in compile time, since the `guesses` it's expecting a `Dog` type, not the `Animal` type. when we bind it to the supertype of `Dog`, the compiler will infer it to `Animal` type, so `cotravariant type` for `Animal`, the `Cat` type is also matched. |
问题2:
1 |
问题是fparam没有直接使用。它在EDOCX1的论证中(0),因此它的方差是翻转的。举例来说,让我们看看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |