-
Notifications
You must be signed in to change notification settings - Fork 41
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: Why isn't Eq
implemented for Ipld
data type?
#171
Comments
The reason are probably the floats. Though as the IPLD forbids non-numeric floating point numbers (such as NaN), it should be possible to implement it manually. |
I'm taking this to mean a PR will be accepted that implements it manually. |
A problem I haven't thought about before seeing the PR is: Currently we don't enforce that there are no non-numeric numbers on the data model level. So how do we deal if someone is using a non-numeric value? Do we we just document it properly, that then equality might not work as expected? Should we put debug inserts in there? Any other ideas? Thoughts from other would be appreciates (cc @Stebalien). |
Is there a way to prevent the export of the individual enum constructors and use smart constructors that forbid the use of NaN and Infinity? That's the way I'd do it in Haskell. This would prevent manual construction and enforces that |
So it appears Rust does not support private constructors for enums. I will adjust the PR to newtype f64 into a value that ensures finiteness. |
I'd simply define Really, equivalence should be defined as |
(which assumes NaN canonization, but we should be doing that anyways) |
Hm. Of course, we currently don't accept those in DAG-CBOR (per spec) then accept them in the implementations... It would be convenient to just accept them and be done with it. |
I just discovered that f64 got |
Implement the `Eq` trait for the `Ipld` enum. NaN floats are never equal to another. Though in the Ipld Data model they are forbidden. This means that we can implement `Eq` for it. As it's currently not strictly enforced that an `Ipld::Float` does not contain a NaN, we make at least sure that in case we would encounter it, that it is treated as equal. For more information about the dicussion about this topic, see ipld/libipld#171.
Implement the `Eq` trait for the `Ipld` enum. NaN floats are never equal to another. Though in the Ipld Data model they are forbidden. This means that we can implement `Eq` for it. As it's currently not strictly enforced that an `Ipld::Float` does not contain a NaN, we make at least sure that in case we would encounter it, that it is treated as equal. For more information about the dicussion about this topic, see ipld/libipld#171.
I see that
PartialEq
is implemented (via derivation), however, I don't see any annotation in the source for whyEq
cannot be implemented. Does this have something to do withNull
?The text was updated successfully, but these errors were encountered: