Scala Can';t将类型投影用于递归(f有界)类型
当使用从一个f-有界类型到另一个f-有界类型的投影时,我得到了一个我不理解的类型错误。可能是,但我不确定 设置很简单:Scala Can';t将类型投影用于递归(f有界)类型,scala,type-projection,bounded-quantification,Scala,Type Projection,Bounded Quantification,当使用从一个f-有界类型到另一个f-有界类型的投影时,我得到了一个我不理解的类型错误。可能是,但我不确定 设置很简单: trait Foo[F <: Foo[F]] { type I <: Foo[I] } 为什么会这样?有解决办法吗 事实上,它似乎是一种变体,无法解释发生了什么 编辑:例如,以下编译: trait Test { def apply[F <: Foo[F] { type I = I1 }, I1 <: Foo[I1]]: Unit = bar
trait Foo[F <: Foo[F]] {
type I <: Foo[I]
}
为什么会这样?有解决办法吗
事实上,它似乎是一种变体,无法解释发生了什么
编辑:例如,以下编译:
trait Test {
def apply[F <: Foo[F] { type I = I1 }, I1 <: Foo[I1]]: Unit = bar[I1]
def bar [F <: Foo[F]]: Unit = ???
}
特质测试{
def apply[FOk,所以我检查了我现有的代码库,直到我发现以前使用过这个变通方法:
trait Foo[F <: Foo[F]] {
type I <: Foo[I]
type Tx <: Txn[F]
}
trait Txn[F <: Foo[F]] {
val foo: F
}
trait Test {
def apply[F <: Foo[F]](implicit tx: F#Tx): Unit = {
val foo: F = tx.foo
bar[F, foo.I](tx)
}
def bar[F <: Foo[F], I <: Foo[I]](implicit tx: F#Tx): Unit = ???
}
trait Foo[F
trait Foo[F <: Foo[F]] {
type I <: Foo[I]
type Tx <: Txn[F]
}
trait Txn[F <: Foo[F]] {
val foo: F
}
trait Test {
def apply[F <: Foo[F]](implicit tx: F#Tx): Unit = {
val foo: F = tx.foo
bar[F, foo.I](tx)
}
def bar[F <: Foo[F], I <: Foo[I]](implicit tx: F#Tx): Unit = ???
}