Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't Scala Lists have an Ordering?

Tags:

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.

like image 250
Craig P. Motlin Avatar asked Dec 20 '10 19:12

Craig P. Motlin


1 Answers

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

like image 94
Martin Odersky Avatar answered Sep 18 '22 11:09

Martin Odersky