Why don't Scala Lists have an Ordering?

Craig P. Motlin picture Craig P. Motlin · Dec 20, 2010 · Viewed 8.1k times · Source

Is there a reason why there is no implicit Ordering for Lists in Scala?

val lists = List(List(2, 3, 1), List(2, 1, 3))
lists.sorted

error: could not find implicit value for parameter ord: Ordering[List[Int]]

EDIT

Yes, my question is why there is no built-in Ordering that's already implicitly in scope. To me, it seems obvious that the second list should be "less than" the first list since the items at 0 are equal and the second list has the lower item at 1. I was wondering if maybe it's that there's no good answer when the Lists are two different sizes.

Answer

Martin Odersky picture Martin Odersky · Dec 20, 2010

I think it's an oversight. Lexicographic ordering does make sense on Seqs. We should add it to the standard library.