Strange error with higher-kinded types in scala 2.10.0 (works with scala 2.9.2)

可紊 提交于 2019-12-22 06:28:58

问题


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)
}

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)

What happens here? What was changes in higher-kinded types in Scala 2.10?

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)
}

回答1:


Looks like a bug, most likely: https://issues.scala-lang.org/browse/SI-5330

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



来源:https://stackoverflow.com/questions/15265741/strange-error-with-higher-kinded-types-in-scala-2-10-0-works-with-scala-2-9-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!