Scala 让隐式解析和类型投影发挥作用?可能需要一个解决办法
我已在2.10.4和2.11.1中确认这是一个问题 我的目标是结合隐式和类型投影。。。我想知道是否有办法让它发挥作用Scala 让隐式解析和类型投影发挥作用?可能需要一个解决办法,scala,Scala,我已在2.10.4和2.11.1中确认这是一个问题 我的目标是结合隐式和类型投影。。。我想知道是否有办法让它发挥作用 trait Plat[P <: Plat[P]] { type Keyed[_, _] } class MPlat extends Plat[MPlat] { type Keyed[K, V] = (K, TraversableOnce[V]) } trait Prod[P <: Plat[P], T, This <: Prod[P, T, This
trait Plat[P <: Plat[P]] {
type Keyed[_, _]
}
class MPlat extends Plat[MPlat] {
type Keyed[K, V] = (K, TraversableOnce[V])
}
trait Prod[P <: Plat[P], T, This <: Prod[P, T, This]] {
def name(str: String)(implicit wrap: Wrapper[P, T, This]): This = wrap(this)
}
trait KProd[P <: Plat[P], K, V] extends Prod[P, P#Keyed[K, V], KProd[P, K, V]]
object Wrapper {
implicit def keyedWrapper[P <: Plat[P], K, V]: Wrapper[P, P#Keyed[K, V], KProd[P, K, V]] =
new Wrapper[P, P#Keyed[K, V], KProd[P, K, V]] {
override def apply(p: Prod[P, P#Keyed[K, V], KProd[P, K, V]]): KProd[P, K, V] = throw new Exception("we made it!")
}
}
sealed trait Wrapper[P <: Plat[P], T, This <: Prod[P, T, This]] {
def apply(p: Prod[P, T, This]): This
}
事实上,这是可行的:
keyedWrapper[MPlat, Int, Int](new Prod[MPlat, (Int, TraversableOnce[Int]), KProd[MPlat, Int, Int]] { })
我认为这是scala类型检查器中的一个bug,但是我想知道是否有一个解决方法(同时保持相同的语义)可以使这个解析成功地工作
keyedWrapper[MPlat, Int, Int](new Prod[MPlat, (Int, TraversableOnce[Int]), KProd[MPlat, Int, Int]] { })