Equality
Doug Lea
dl at cs.oswego.edu
Tue Dec 22 14:01:06 UTC 2015
On 12/21/2015 05:33 PM, John Rose wrote:
> Two events like that certainly call for generalization.
> Algebraists will be eager to suggest other any-fied relations,
> so we want to support open-ended extension mechanisms.
> This is one reason value types are envisioned to interoperate
> with interfaces.
>
I'm not sure about generalization. There's only the beginnings
of academic work on static analysis and validation of functional
properties (like those below pasted from something else I had around).
In the mean time, probably the best we could do is add annotations
(like @Symmetric) that would have to be trusted in order to
be effective. Or, nearer term, focus only on equals and compareTo.
for function f, predicate p, and valid arguments a, b, c:
Idempotent: f(a) == f(a)
Deterministic: if (a == b) then f(a) == f(b)
Injective: if (a != b) then f(a) != f(b)
Commutative: f(a, b) == f(b, a)
Associative: f(f(a, b), c) == f(a, f(b, c))
Monotonic: if (a <= b) then f(a) <= f(b)
Reflexive: p(a, a)
Irreflexive: !p(a, a)
Symmetric: if (a == b) then p(a, b) == p(b, a)
Antisymmetric: if (a != b) then p(a, b) != p(b, a)
Transitive: if (p(a, b) and p(b, c)) then p(a, c)
-Doug
More information about the valhalla-spec-experts
mailing list