-
Notifications
You must be signed in to change notification settings - Fork 326
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
Add Comparator conversion for all types #4067
Conversation
e997c5f
to
0d6560f
Compare
0d6560f
to
a170e53
Compare
- Revert changes in Any, so that we have still the old behavior - Define new Any.=== , Any.<== and Any.>== operators as extension methods in Eq.enso - Make Any.hash_code accessible as a temporary workaround
- Must not contain `self` keyword.
- We should remove Eq_Spec in the future.
fd14bb8
to
93ed516
Compare
…atom with custom comparator is encountered. - EqualsNode calls `Any.==`. - HashCodeNode calls `Comparable.hash_callback`.
… members to Eq/Hash nodes
This reverts commit c0e08e9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional approval based on our internal discussion.
Please file a follow up ticket for removing the need to import Standard.Base.Data.Any.Any
when performing simple equality operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really glad to see this endeavor converging! I might have some suggestions for a change, but I believe it is more important to integrate this while we are green and only then solve problems that might appear anywhere.
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Ordering.enso
Outdated
Show resolved
Hide resolved
- If hash(x) != hash(y) then x != y | ||
- Consistency: if x == y then x == y for all the subsequent invocations. | ||
- Symmetry: if x == y then y == x | ||
- Reflexivity: x == x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflexivity should be enforced. Meta_is_same_object x y
implies x == y
.
- If x == y then hash(x) == hash(y) | ||
- If hash(x) != hash(y) then x != y | ||
- Consistency: if x == y then x == y for all the subsequent invocations. | ||
- Symmetry: if x == y then y == x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symmetry could be enforced. Just like we check hash
code consistency we could also verify (from time to time) that x == y
and y == x
is consistent.
Critical performance improvements after #4067 # Important Notes - Replace if-then-else expressions in `Any.==` with case expressions. - Fix caching in `EqualsNode`. - This includes fixing specializations, along with fallback guard.
Pull Request Description
Add
Comparator
type class emulation for all types. Migrate all the types in stdlib to this newComparator
API. The main documentation is inOrdering.enso
.Fixes these pivotals:
Important Notes
equals
andhash
methods on their custom comparators.compare_to
overrides were replaced by definition of a custom ordered comparator.x.compare_to y
method were replaced withOrdering.compare x y
.Ordering.compare
is essentially a shortcut forComparable.from x . compare x y
.Any
isDefault_Unordered_Comparator
, which just forwards to the builtinEqualsNode
andHashCodeNode
nodes.x
, one can get its hash withComparable.from x . hash x
.hash
as hidden as possible. There are no other public methods to get a hash code of an object.x
andy
can be done either byOrdering.compare x y
orComparable.from x . compare x y
instead ofx.compare_to y
.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.