[erlang-bugs] Maps equality failure / Maps merge failure
Kostis Sagonas
kostis@REDACTED
Wed Mar 25 00:16:08 CET 2015
On 03/24/2015 11:00 PM, Jesper Louis Andersen wrote:
> Erlang/OTP 17 [erts-6.3.1] [source-a1520d8] [64-bit] [smp:8:8]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V6.3.1 (abort with ^G)
> 1> L = [{-1,0},{0.0,0},{0,0},{1,0}].
> [{-1,0},{0.0,0},{0,0},{1,0}]
> 2> lists:sort(L).
> [{-1,0},{0.0,0},{0,0},{1,0}]
> 3> lists:sort(maps:to_list(maps:from_list(L))).
> [{-1,0},{0,0},{0.0,0},{1,0}]
> 4> v(2) =:= v(3).
> false
> 5> maps:to_list(maps:from_list(L)).
> [{-1,0},{0,0},{1,0},{0.0,0}]
>
> In other words, factoring L through a map makes the comparison and the
> sort go wrong.
The above may seem a bit weird at first but is not at all strange given
that lists:sort/1 does not sort according to the (total) term order:
Eshell V6.3.1 (abort with ^G)
1> lists:sort([0, 0.0]).
[0,0.0]
2> lists:sort([0.0, 0]).
[0.0,0]
and maps:to_list/1's manual page reads:
to_list(Map) -> [{Key, Value}]
Types:
Map = #{}
Key = Value = term()
The fuction returns a list of pairs representing the key-value
associations of Map, where the pairs, [{K1,V1}, ..., {Kn,Vn}], are
returned in arbitrary order.
Kostis
PS. However, the manual has a typo: "fuction" should read "function" :)
More information about the erlang-bugs
mailing list