dok/spec/check-value-equality
Problem
Equality done right is hard to do in many PL. If done correctly, it can be too much slow, and if done quickly, sometime it cannot respect all good algebraic properties that one expect.
Eq
class
class Eq [
fun equal(other::Self)::Bool -abstract
:^# the `other` is of the exactly the same type
]
Equality on References
The equality between references is managed automatically, using the equality on the values of the same type.
Equality on compound values
Equality on complex/compound data as lists, arrays, strings is difficult to specifiy because:
- if it is correct it is slow
- if it is fast, it can be incorrect from a mathematical/algebraic point of view
Strings can be of different formats, and there can be tricks for comparing them. So ad-hoc code can be written for comparing them, giving some combination of type combinations.
But, in practice, one compare in real code only small values. For complex values, if equality is needed in some algo, one use an alog managing also the details for fast equality comparison. For example the algo maintain a dictionary of strings, or strings are compacted by suffix, or there is some efficient index, or there is a check after delta upgrades of data. So the “equality” test become part of the algo.
So Dok had to:
- support
Eq
only for basic values - help the user to inject ad-hoc equality management using indexes and special support data-structures in different algo, reusing knowing tecniques