jamii
09/01/2024, 3:17 AMa == b
does not imply that f(a) == f(b)
.
◦ If [a: 0, b: 1] == [b: 1, a: 0]
then we must have struct[a: i64, b: i64] == struct[b: i64, a: i64]
, but we still have to remember that the field order is different, which implies that type equality can't rely on interning and pointer comparison.
• Order affects equality.
◦ Sets become surprising / less useful.
◦ If I want to add query planning, I can't promise that f(db) == optimize-query(f)(db)
.jamii
09/01/2024, 3:17 AMjamii
09/01/2024, 3:17 AM* Order isn't observable at all.
* Iteration order is either non-deterministic or expensive.
* Determism can be manually recovered by storing both a map and a list of keys, but at the cost of storing two copies of each key.
* Order is observable.
* Order doesn't affect equality.
* Equality is not extensional ie `a == b` does not imply that `f(a) == f(b)`.
* If `[a: 0, b: 1] == [b: 1, a: 0]` then we must have `struct[a: i64, b: i64] == struct[b: i64, a: i64]`, but we still have to remember that the field order is different, which implies that type equality can't rely on interning and pointer comparison.
* Order affects equality.
* Sets become surprising / less useful.
* If I want to add query planning, I can't promise that `f(db) == optimize-query(f)(db)`.
Kartik Agaram
pairs
and ipairs
?George
09/01/2024, 5:31 PMjonathoda
09/01/2024, 8:43 PMshalabh
09/02/2024, 2:11 AMjonathoda
09/02/2024, 4:11 PMKartik Agaram
jonathoda
09/02/2024, 7:15 PMGeorge
09/02/2024, 7:30 PMjamii
09/03/2024, 8:47 PMbecause it needs to support iterationWell, one solution to the dilemma is just not supporting iteration on maps/sets. If you want to iterate you have to keep a list of keys separately.
jamii
09/03/2024, 8:53 PMHave you considered two iterators, akin to Lua'sBut the order of iteration is still observable, no? This does actually cause problems in practice. Eg to get reproducible builds a lot of compilers had to be refactored to never iterate over hashmaps. If equality doesn't take iteration order into account then it also makes memoization hard:andpairs
?ipairs
>>> a = {'x': True, 'y': True}
>>> b = {'y': True, 'x': True}
>>> def f(x):
... return ''.join(x.keys())
...
>>> a == b
True
>>> f(a) == f(b)
False
jamii
09/03/2024, 8:55 PMjamii
09/04/2024, 5:19 AMordering interferes with transparent query optimization. I refuse to let performance override usabilityIf you sort the keys that's actually less of a problem. You just have to sort at the end (and maybe before aggregations that you can't prove are commutative). But being able to observe insertion order means that you can't reorder loops into joins, which is a much bigger problem.
Tom Larkworthy
09/04/2024, 7:23 AM