-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: please clarify equals/hashCode/toString philosophy as stated in README #50
Comments
Essentially it is because those methods (all object methods) breaks parametricity which is a very important property to be able to reason about types and code. To quote @tel: If I have a type (x, y) -> x or (x, y) -> y that’s a trivial example, but it scales very well and can eliminate huge swaths of potential implementations and vastly improve type-driven reasoning. On the other hand, if you account for (x, y) -> if (x.hashCode > 1000) x else y Other pitfalls of
For further reading/viewing on why you would want parametricity, I recommend Tony Morris' talks on the topic. Hope it helps! Edit (thanks @TomasMikula): the <A> BiFunction<A, A, A> foo() {
// either:
return (x, y) -> x
// or
return (x, y) -> y
} |
Thank you! I kept glossing over this part of the README and finally just had to ask :). I don't think I have the necessary background to actually understand your answer, but this gives me plenty of direction for further exploration. <3 |
@jbgi I get your point, but class Foo<A> {
BiFunction<A, A, A> f = ??? // this has to be one of
// (x, y) -> x
// (x, y) -> y
// infinite recursion
} but there might also be more information available about class Foo<A extends Bar> {
BiFunction<A, A, A> f = ??? // many more options
}
abstract class Bar {
public int x;
} So maybe instead of static <A> A foo(A a1, A a2) {
// now my only options are
// return a1;
// return a2;
// infinite recursion, e.g. return foo(a1, foo(a2, a1));
} |
@TomasMikula totally, thanks for the clarification; I fail to mention that |
The README says:
If you have a minute, can you please clarify what this means? Specifically, why is not having these methods "safe and consistent".
Thank you!
The text was updated successfully, but these errors were encountered: