[erlang-questions] map elements in defined order
Stanislaw Klekot
erlang.org@REDACTED
Fri Oct 27 22:25:51 CEST 2017
On Fri, Oct 27, 2017 at 09:36:58PM +0200, Richard Carlsson wrote:
> 2017-10-27 17:45 GMT+02:00 Sverker Eriksson <sverker.eriksson@REDACTED>
> >
> >
> > How would you order #{1 => x, 1.0 => y} and #{1 => y, 1.0 => x}
> > if you can't order 1 and 1.0?
> >
>
> As long as we're talking about the arithmetic term order (<, >, ==), I
> don't see why they would need to be. Look at tuples:
>
> {1, 1.0} < {1.0, 1}.
> false
> {1, 1.0} > {1.0, 1}.
> false
> {1, 1.0} == {1.0, 1}.
> true
> {1, 1.0} =:= {1.0, 1}.
> false
>
> Maps ought to behave analogously, in the arithmetic ordering.
The problem is, the tuples you provide and comparison operators (<, >,
=<, >=, and == (not =:= one)) form a well-defined partial order (total
order, actually); mainly, if A =< B and B =< A, then A == B. Being
a partial order is a very important property of Erlang's type system,
one that was quite explicitly baked in the VM and is used in many
different places.
--
Stanislaw Klekot
More information about the erlang-questions
mailing list