>
> When these structures use Structual Ordering, they will work differently
> from when using Logical Ordering.
> An example: If I want to keep a top ten of highscores, I only want to
> order %HighScore{}'s based on their score, and not on the user that
> archieved the score or on the time the score was arrived at. A 'custom
> ordering' is exactly what this proposal wants to allow to be made.
>

If you want custom ordering, then a protocol is not the solution because
they are global. Imagine you have a collection of users. Sometimes you want
to order them by age, sometimes by name. Sure, you can implement the
Comparable protocol for %User{} in a way that makes sense most times, but
that doesn't exclude the fact you still want custom ordering via functions.

In fact, using a ordering that does not work across types would be
detrimental in Elixir, since we do allow a list to have any data type. For
example, if Enum.sort/1 used the proposed protocol, it would be unable to
work on heterogeneous collection by default. If tree data types used that
as well, we would be unable to have heterogenous trees, etc.

My point is: we already have an ordering mechanism. Sure, it has flaws, but
there is little benefit in replacing it by a version that is slower and
works only on homogenous collections. The answer is to continue supporting
custom ordering functions. If we want to standardize the use of :eq | :lt |
:gt, then let's do that by providing functions that work on those types.
The answer is not a Comparable protocol.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Jp4d6dNTYJH9wqODSq0PcmrLo%2Bz3Gmk5e2eVZ4qzbWFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to