This page is no longer maintained — Please continue to the home page at

import compare-methods of Ordering

No replies
Joined: 2010-05-23,
User offline. Last seen 1 year 19 weeks ago.

See the following code snippet:

case class Box[A](a: A)
//extends Ordered[A] {
// def compare(a: A) =
// a.hashCode

object Box {
implicit def ord[A]: Ordering[Box[A]] =
new Ordering[Box[A]] {
def compare(x: Box[A], y: Box[A]) =

class Sorter[A](a: A*)(implicit ord: Ordering[A]) {
import ord._
a(0) > a(1) // works fine

import Box._

new Sorter[Int]
new Sorter[Box[Int]]
Box(3) > Box(7) // does not work, can't find implicit conversion

In class `Sorter` it is possible to access the implicit conversions of
`Ordering` which allows the use of the compare-symbols. But I haven't
found a way to make these methods accessible outside of class `Sorter`.
It is possible to extend `Box` with `Ordered`, but I want avoid this.

Is it possible to access the compare-methods of Ordering without
explicitly defining an Ordering?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland