Struct comparisons already throw a warning 
<https://github.com/elixir-lang/elixir/blob/741dfda9f4be898c647426493f1d17fb9a4b9c53/lib/elixir/src/elixir_expand.erl#L1161-L1165>
 
in Elixir, as it does not make a lot of sense to compare them (except in 
some very specific cases like date/time):

warning: invalid comparison with struct literal ~N"2018-10-19 
> 21:35:18.005355". Comparison operators (>, <, >=, <=) perform structural 
> and not semantic comparison. Comparing with a struct literal is unlikely to 
> give a meaningful result. Modules typically define a compare/2 function 
> that can be used for semantic comparison
>

But currently this happens only when literal structs are used. For example, 
when using `Enum.sort` to sort a list of dates, this warning is not raised. 
I know there already has been some discussion on this 
<https://groups.google.com/forum/#!topic/elixir-lang-core/eE_mMWKdVYY>, but 
I believe OvermindDL's suggested approach 
<https://github.com/elixir-lang/elixir/pull/7274#issuecomment-361362861> to 
have a Comparable protocol is much better. Kernel's comparison operators 
would delegate to this protocol, with implementations for common things 
like Date/Time, and letting it simply throw Protocol.UndefinedError for 
structs which do not have explicitly implemented it.

-- 
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/9535bd51-ae61-442a-90fe-c25632d472f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to