Allow int's to be dictionary keys
ertong opened this issue ยท 5 comments
Sometimes, key of the dictionary can be an integer (like id or timestamp). And it could be usefull not to stringify them.
As far as I understood, it is enough to allow Ax, Bx for the keys to implement this ... does not require any major specification change.
This raises the question of whether a dict with integer keys is distinct from one with string keys or if they can coexist within the same map. Personally I would prefer them to be distinct - all string keys or all integer keys.
It would also be worth thinking about what other types make sense as allowable keys; dicts and arrays make sense to exclude, but what about bools, or floats.
Floats are no good as keys - the comparison operation is tricky, and it would probably lead to big issues in future ;)
Bools are not too interesting, you can have keys 0 and 1 instead. Null, NaN, +Inf, -Inf
could be interesting though! ๐
@ertong WDYT?
Honestly, look, for example, on Java you can make HashMap with any key: string, int, double, boolean, any Object. It is not a problem to have any map you want.
For sure, you should not make a map with a double key. But I do not see any problem to be able to. Anyway, this dict will be enumerated as key-value list. In some cases it can be handy.
So, I do not see a problem to allow any available key type.
But, the most useful are ints and strings treating 22 and "22" as different keys.
Here's the initial Dict
specification: https://github.com/vshymanskyy/muon/blob/master/docs/README.md#dictionary
LMK your thoughts or if more details are needed.