2

In my scala eclipse worksheet I do:

val values: List[(Char, Int)] = List(('z', 7), ('b', 6))
                                                  //> values  : List[(Char, Int)] = List((z,7), (b,6))
val sortedValues = values.sortBy(_._1)          //> sortedValues  : <error> = List((b,6), (z,7))

I cannot understand why the sortBy function gives an <error> or how do find more information about it.

When I put the same code into a scala class, I get:

diverging implicit expansion for type scala.math.Ordering[B] starting with method Tuple9 in object Ordering

I see other threads with this error. But they are different cases.

Any help appreciated

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
More Than Five
  • 9,959
  • 21
  • 77
  • 127
  • Do you have any weird import that could conflict with Ordering of your tuples or the tuple's contents? If you try it on the REPL, do you get the same error? For me it works fine on the REPL, scala 2.10.1. Maybe it's a worksheet issue? – pagoda_5b May 09 '13 at 12:58
  • Looks like the implicit ordering is not properly resolved, sortBy is defined as follow : def sortBy[B](f: (A) ⇒ B)(implicit ord: math.Ordering[B]): List[A] Have you tried using a longer version of your sorting function ? Like values.sortBy(i => i._1) ? – vptheron May 09 '13 at 13:53
  • 1
    What version of scala are you running? If you add that code directly to the REPL, do you get the same error? – rsan May 09 '13 at 18:13

0 Answers0