After looking through the source of Elixir's `Enum` module and Erlang's 
`:lists` module, I now know that `:lists.sort` is implemented in plain 
Erlang, which means that it would also be possible to write multiple 
versions in Elixir (Most notably, both an low-to-high and high-to-low 
version). `Enum.sort(list) |> Enum.reverse()` is then slower than a 
hypothetical `Enum.sort_reverse(list)` by a constant factor. It might be 
interesting to benchmark this, but that is completely out of scope of the 
Comparable interface.

---

Going back to the core of this issue, I'd like for there to be a simple 
function `compare` with an accompanied Protocol, which ensures that the 
comparison return values are standardized. This would significantly improve 
compatibility of libraries. I think this is a standardization that we 
should embrace quickly, before the APIs of the publicly available libraries 
dift further apart and become near-impossible to reunite in a 
backwards-compatible fashion. 

I'd like to hear who is in favour and who is against of this very concrete 
proposal.


On Friday, June 9, 2017 at 2:37:39 PM UTC+2, Michał Muskała wrote:
>
> On 9 Jun 2017, 14:28 +0200, Wiebe-Marten Wijnja <[email protected] 
> <javascript:>>, wrote:
>
>
> We could change `Enum.sort` to use `&Kernel.lte?/2` by default, rather 
> than `&<=/2`. Although this might have slight efficiency implications for 
> existing applications, I think it would uphold the Principle of Least 
> Surprise better.
>  
>
>
> This would have huge performance implications. Enum.sort/1 and Enum.sort/2 
> have completely different implementations. Enum.sort/2 is about 2.5 times 
> slower (when provided with &<=/2 as comparator).
>
> Michał.
>

-- 
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/b13f4ca3-8686-4cb8-997b-88b876c84fb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to