You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Equality is always a symmetric relation, and I think we should implement an exception for == so that for instance the method Vector == ZZ will automatically also be used if ZZ == Vector is called.
Here is a potential implementation:
eq0 = lookup(symbol==, Thing, Thing)
Thing == Thing := (a,b) -> (
iflookup(symbol==, class b, class a)
=!= lookup(symbol==, class a, class b)
then b == a else eq0(a,b))
I don't like it very much, but it works:
i1 : eq0 = lookup(symbol==, Thing, Thing);
i2 : Thing == Thing := (a,b) -> (
iflookup(symbol==, class b, class a)
=!= lookup(symbol==, class a, class b)
then b == a else eq0(a,b));
i3 : 1 == vector {1,2}
stdio:2:149:(3):[1]: error: no methodfor binary operator == applied to objects:
1 (ofclassZZ)
2
== | 1 | (ofclassZZ )
| 2 |
i4 : Vector == ZZ := (v,f) -> matrix v == f;
i5 : 1 == vector {1,2}
stdio:4:34:(3):[2]: error: matrices have different shapes
i6 : 1 == vector {1}
o6 = true
The text was updated successfully, but these errors were encountered:
A more involved but perhaps better solution might be to change specifically how methods on == are installed, i.e. change Type == Type := Function which has the unfortunate method key ((symbol ==, symbol =), Type, Type) to reorder the two types based on which type is younger, and also change lookup to reorder the keys based on seniority as well. Note that the method is always installed on the younger of the two objects anyway (e.g. in the example above Vector#(symbol ==, Vector, ZZ)).
Perhaps a more generalized version of this solution is to add a Symmetric option to method which would tell lookup and installMethod to reorder the types and inputs based on seniority of the types first.
Equality is always a symmetric relation, and I think we should implement an exception for == so that for instance the method
Vector == ZZ
will automatically also be used ifZZ == Vector
is called.Here is a potential implementation:
I don't like it very much, but it works:
The text was updated successfully, but these errors were encountered: