3 ms·
I don't know why implicit equality is relevant here. The idea is that you'd explicitly recognize that there are multiple forms of equality, and that the one you
by Retra 10y ago
I don't know why implicit equality is relevant here. The idea is that you'd explicitly recognize that there are multiple forms of equality, and that the one you want depends almost entirely on the problem domain. So you shouldn't have any 'implicit' or 'preferred' equality. You'd always let the call site dictate which equality relation it needs.
You asked for a non-structural equality relation, and I gave you a whole class of them. There are many more. There isn't even one kind of 'structural equality': are two things equal if they have the same memory layout? The same AST representation? What if the layout depends on the allocator? What if they are identical but must be treated differently through aliases?
- jstimpfle 10y agoYou agree it should be explicit. But notice that explicit hash equality is just hashing followed by structural equality. Considering different abstraction levels like AST or memory layout: This is moving up and down the levels of abstraction. It's conventional wisdom that you shouldn't do this in a single context (like a function, module, or even a programming language). But it's a good point - powerful languages like C present all these levels at once. In other words, there is often an impedance mismatch. Structural equality might be not quite the same to the compiler and to the programmer.
- Retra 10y agoAnd structural equality is just a special (also arbitrary) kind of hash equality. You still have to specify what kind of structure you're comparing. The "structural equality" that you are referring to is vague not uniquely determined.
- jstimpfle 10y agoYou made great points, and I've realized that the compiler/interpreter doesn't always know what's the part of the context that we are actually interested in. There's often too much context available and it's not always easy to throw away the information that we're not interested in. However when one does manage to make a function to a structural representation that contains exactly the interesting things, then equality is this function followed by structural equality.