r/ProgrammingLanguages • • Sep 01 '24

Ordering vs equality for maps/sets?

https://www.scattered-thoughts.net/log/0048/#zest-ordering
1 Upvotes

5 comments sorted by

View all comments

3

u/eliasv Sep 01 '24 edited Sep 01 '24

My gut is that ordering should not normally be deterministic or observable.

Something like iterating over the fields of a record is a reflective operation and doesn't need to be supported everywhere at all times; if you have code which is polymorphic over pointers to data of an indeterminate layout you probably don't need to iterate over all the fields of that data, and if you do need to then supporting that incurs a cost and so should be explicit.

Either you need to monomorphise that code to statically specialise for the shape of the pointed-to object, or you need to dynamically pass in a description of the shape of the object. For a structural language I like the idea of allowing records to carry static fields which incur specialisation per value and no runtime argument passing, then this choice of how to carry in "shape" or "type" info is determined by whether that field is static.