问题描述
此代码使用 Scala 2.9.2 编译:
This code compiles with Scala 2.9.2:
trait HK {
type Rep[A]
def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]])
def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps)
}
但是在 Scala 2.10.0 中它不会编译并出现以下错误(启用了更高级的语言功能):
But with Scala 2.10.0 it doesn't compile with the following error (higherKinded language feature is enabled):
[info] Compiling 1 Scala source to /home/klyuchnikov/code/hk/target/scala-2.10/classes...
[error] /home/klyuchnikov/code/hk/src/main/scala/HK.scala:6: type mismatch;
[error] found : HK.this.Rep[List[(A, B(in method doUnzip1))]]
[error] required: HK.this.Rep[List[((A, B(in method doUnzip1)), B(in method unzip1))]]
[error] def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps)
这里发生了什么?Scala 2.10 中高级类型有哪些变化?
What happens here? What was changes in higher-kinded types in Scala 2.10?
P.S. 如果我显式传递类型参数,则此代码将编译:
P.S. If I pass type parameters explicitly, then this code compiles:
trait HK {
type Rep[A]
def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]])
def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1[A, B, List](ps)
}
推荐答案
看起来像一个错误,很可能:https://issues.scala-lang.org/browse/SI-5330
Looks like a bug, most likely:https://issues.scala-lang.org/browse/SI-5330
它应该在 Scala 2.10.1 中修复,如果你迫不及待,你可以尝试发布候选:http://www.scala-lang.org/2.10.1-RC3
It should be fixed in Scala 2.10.1, if you can't wait you may try release candidate:http://www.scala-lang.org/2.10.1-RC3
这篇关于scala 2.10.0 中高级类型的奇怪错误(适用于 scala 2.9.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!