-
Notifications
You must be signed in to change notification settings - Fork 228
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
Heterogeneous equality #54
Comments
Isn't the type of any list just 'list'? Which means comparing two lists is still A x A -> bool (where A is list)? |
|
Yes, you're correct, lists are unparameterized at runtime, so list equality typechecks correctly with homogeneous equality. This is entirely an issue of explaining list equality in terms of elementwise equality, and [x] == [y] is just an extreme case of that. |
It looks like I am actually of the opinion CEL should match json, python, SQL, Firestore, c++, java, etc and allow full comparisons between different number types (while still not allowing implicit conversion or heterogeneous arithmetic). |
BTW, a deterministic 'total ordering' is a land mine :-). It is much better to leave it undefined, and the 'iteration' order of a map should be not just undefined, but randomized between invocations. Also note that comparisons are pretty much always independent of any 'total ordering' provided because of NaN in floats. "hi" < 1 should always be undefined. You basically end up with 3 classes of operators:
basically, where these overlap, they must be consistent or produce 'undefined'. You can see this distinction in pretty much every language (for unfortunately good reasons) |
The axiom of choice is actually a great example of how total ordering is a fundamental issue in human math ;-) |
Ahh, just remembered the other wrinkle, hash values and map keys. |
FYI, python ignores float vs int for dict keys:
|
(also note that python 3 explicitly removed global ordering so ["hi] > [1] is now an error.) |
Let's suspend consideration of a trans-type total order, whether exposed as an operator or not. I don't think it's adding clarity to this discussion. We've recently identified more language features that would be convenient to explain in terms of a heterogeneous equality: the in operator. Restating for the record: because there's no way for a CEL program to depend on a subexpression being an error, it's safe to convert error behavior to non-error (in the sense that all programs that produce a value will produce the same value), but more problematic to convert one value to another. So if we make heterogeneous equality legal, we shouldn't later switch the behavior of CEL, as a basic design decision, has decided to avoid automatic conversion between numeric types and mixed-type arithmetic operations. Allowing In discussions, Tristan raised the issue of JSON conversions: some JSON parsers convert fraction-less numbers to an integer type, and some CEL deployments might want to directly import these imported JSON results without intermediate conversion to a |
I'm working on a proposal for numeric type coercion and a heterogeneous null comparison which should fix almost all of the core usability issues outside of protobuf equality which is a larger and separate topic. I'll get a bit of language council review on it and then submit the proposal for external consumption here. |
Also affects issue #208 |
In the conformance tests there's several heterogenous comparisons supported at runtime (albeit not at typecheck time):
However, the spec states: "Equality and inequality are homogeneous; comparing values of different runtime types results in a runtime error. Thus 2 == 3 is false, but 2 == 2.0 is an error.". What's the current take on this? |
And simultaneously the tests contain
|
@jsannemo Hi Johan, with the changes proposed and accepted in https://github.com/google/cel-spec/wiki/proposal-210, as well as a forthcoming approval for changes in protobuf equality at runtime, the stance is as follows:
Most of these changes are in development, but not yet surfaced in the spec or the configuration options. |
Thanks for the pointer! I had missed the wiki totally. |
Since
[1, "foo"]
is a valid list and_==_
is defined on lists,[1, "foo"] == ["foo", 1]
should evaluate tofalse
. It would be least surprising if list equality was determined by elementwise equality. Equivalently,[x] == [y]
should have the same meaning asx == y
. Therefore,_==_
should have signatureA x B --> bool
.Similarly,
_!=_
should work on heterogeneous types.Restricting equality to homogeneous types was meant to prevent user errors. After all, heterogeneously
1 == 1u
evaluates surprisingly tofalse
. However the type checker can work with a stricterA x A --> bool
signature for equality, catching these errors.We might want to make heterogeneous order operators (
_<_
and friends) too. We'll want an ordering across all values for deterministic map comprehensions, so why not expose it to users? The surprising consequences (e.g. if int < uint, then 1u < 2) can again be mitigated by having the type checker work heterogeneously.The text was updated successfully, but these errors were encountered: