[erlang-questions] map elements in defined order

zxq9 zxq9@REDACTED
Fri Oct 27 15:47:28 CEST 2017

On 2017年10月27日 金曜日 15:26:22 Sverker Eriksson wrote:
> Yes. All Erlang terms, including maps, have a globally defined, 
> implementation independent, total order.
> The reason, for this "surprising" order of maps, is the alternative of 
> using the normal arithmetic order for keys is much worse.

I am curious, though, why a compound data type was added to the language as a primitive data type. This was the only thing that really bothered me about maps.

Second-class data type, sure. Ordering unknown. Whatever. Same with all the other compound data types that we make up for ourselves.

Having it as a data primitive introduces inconsistency in the language itself, as we either have to have a tradeoff to amortize enforcement of an arbitrary ordering to make comparisons faster, or force an ordering at the time of comparison (and/or serialization, maybe) at the cost of some computation time in order for things to work. That adds one more odd point of weirdness to the language we *never* once worried about before but now need to remember in edge cases where performance matters. In other words, this creates a new edge case for performance, if I understand thing correctly.

Who before was ever seriously considering using dicts as keys to dicts?

"But lists are compound data types!" Sort of. The ordering of a list very often IS its meaning -- thus strings. Not so for maps by their very nature.


More information about the erlang-questions mailing list