简体   繁体   English

Scala发散隐式扩展编译器错误

[英]Scala diverging implicit expansion compiler error

Can someone help me understand the compile error message below? 有人可以帮助我了解下面的编译错误消息吗? I've been looking at this for a while now and I don't understand what's wrong. 我已经看了一段时间了,但我不明白这是怎么回事。

  def makeOrderedLeafList(freqs: List[(Char, Int)]): List[Leaf] = {
    val buff = ListBuffer[Leaf]();
    for(u<-freqs) {
       val v = new Leaf(u._1, u._2)
       buff += v
    }
    buff.toList.sortBy(_.weight) //<= offending line
  }

Error message: 错误信息:

diverging implicit expansion for type scala.math.Ordering[B] starting with method Tuple9 in object Ordering 类型scala.math.Ordering [B]的离散隐式扩展以对象Ordering中的方法Tuple9开头

EDIT: Class declarations look like: 编辑:类声明看起来像:

  abstract class CodeTree
  case class Fork(left: CodeTree, right: CodeTree, chars: List[Char], weight: Int) extends CodeTree
  case class Leaf(char: Char, weight: Int) extends CodeTree

Works for me on scala 2.10.0 在scala 2.10.0上为我工作

import scala.collection.mutable._

then paste in the code you supply above. 然后粘贴上面提供的代码。 makeOrderedLeafList compiles without error and seems to work in the intended way: makeOrderedLeafList编译没有错误,并且似乎以预期的方式工作:

scala> makeOrderedLeafList(List(('a',8),('b',9),('c',99),('d',1)))
res0: List[Leaf] = List(Leaf(d,1), Leaf(a,8), Leaf(b,9), Leaf(c,99))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM