假設以下類型和方法的存在:斯卡拉:F-界多態性愁楚
trait X[A <: X[A]]
case class C extends X[C]
def m(x: PartialFunction[X[_], Boolean])
我希望能夠創造一個PartialFunction傳遞到m
。
第一次嘗試是寫
val f: PartialFunction[X[_], Boolean] = {
case c: C => true
}
m(f)
這種失敗type arguments [_$1] do not conform to trait X's type parameter bounds [A <: X[A]]
。所以,看來我們必須限制X
的類型參數。
第二次嘗試:
val f: PartialFunction[{type A <: X[A]}, Boolean] = {
case c: C => true
}
m(f)
這對失敗的m
因爲PartialFunction[AnyRef{type A <: X[this.A]},Boolean] <: PartialFunction[X[_],Boolean]
是假的應用程序。
是否有任何方式不涉及實際上滿足部分函數的定義和編譯器m
應用程序的編譯器?