路径相关类型的方差技巧
这是针对implicits和路径依赖类型的另一个。我不明白为什么我需要在这里如此冗长:(注意 - 我找到了答案,见下文)
trait B
trait C[X]
trait A { def call[B1 <: B](implicit b: B1): C[B1] }
trait D extends B {
def set(c: C[this.type]): Unit
}
第一次尝试:
def test1(a: A)(implicit d: D: Unit =
d.set(a.call) // found C[D] -- required C[d.type]
第二次尝试:
def test2(a: A)(implicit d: D): Unit =
d.set(a.call[d.type]) // could not find implicit value for parameter b: d.type
第三次尝试:
def test3(a: A)(implicit d: D): Unit =
d.set(a.call[d.type](d)) // works. why so much clutter!?
没有找到相关结果
已邀请:
2 个回复
厘恼轨
:
因此:将
改为
使得
按预期工作。
掀辟髓观粟
吗? Scala的“这种类型”与通常所说的“MyType”不同。请参阅
上的此讨论,以及MyType问题链接的讨论。