Thank you for starting this discussion, Michał. I feel, however, including
examples of code that could be improved by this proposal would strongly
benefit the discussion. I would also like to hear a fair assessment of the
downsides of such feature. A couple come to mind but I won't release
spoilers. :)



*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Sun, Aug 7, 2016 at 10:13 PM, Michał Muskała <[email protected]> wrote:

> Hello everybody,
>
> Today I’d like to address one of annoyances of working with elixir -
> comparing structs. It’s a problem because of two reasons:
> - it’s not widely known that the regular comparison operators do not work
> correctly with structs
> - there’s no standard way of providing custom comparison function.
> This issue is especially apparent in couple libraries, most notably Ecto
> (with calendar types), decimal and with the new standard calendar types.
>
> I propose adding a Kernel.compare/2 function with signature:
> compare(term, term) :: :lt | :eq | :gt
>
> I would propose following properties of the function:
> - inlined implementation for built-in types, only for both arguments of
> the same type
> - for structs the function calls the Comparable.compare/2 protocol function
> - implementation for structs are allowed to return value for two different
> types when it makes sense
> - the protocol is also implemented for built-in types
> - the protocol does not fallback to Any
>
> I’m convinced this will allow for much easier experience when comparing
> structs, even though the VM does not allow to extend the regular comparison
> operators.
>
> 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/836EAED5-CCA7-4144-A14B-E9637140A55C%40muskala.eu.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGnRm4LBKen0DXnr%3Du1TdZ9%3DSh_Uxz5SUoL%2BJSmpyFnVqkkU1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to