-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: cmp: Equal #70161
Comments
Related Issues and Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
A minor nit: in order to correspond to func Cmp[T comparable](a, b T) bool {
if isNaN(a) && isNaN(b) {
return true
}
return a == b
} |
Wouldn't that have unexpected behavior for composite types like arrays, structs, and interfaces? Equal([2]float64{123, 456}, [2]float64{123, 456}) // true
Equal([2]float64{nan, 456}, [2]float64{123, 456}) // false
Equal([2]float64{nan, 456}, [2]float64{123, nan}) // true As far as I can tell, our options are:
|
Good points. I don't know if there is a reasonable way to do this entirely correctly. |
My understanding was that the special case for NaNs in Regardless, it seems like either choice would require specific documentation to say that it surprisingly doesn't conform to Personally I think the best thing to do would be not conform so that it's nothing more than a convenient way to write |
I think it's pretty confusing if |
I retract the proposal then. It's of no use to me if it's not regular |
Proposal Details
I find myself writing this a lot lately. Sometimes multiple times in a module because I don't want to export it or bother with creating
internal/
packages just for this.This comes up whenever you have
Op
andOpFunc
where the latter variant takes an equality function. The body ofOp
just callsOpFunc
with some local copy of the proposed.Even with the shortest possible syntax proposed in #21498 this would still be
(a, b) => a == b
vscmp.Equal[T]
andT
would often be inferred as this is basically always used as the argument to a function.The text was updated successfully, but these errors were encountered: