manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.43k stars 125 forks source link

Implicit equals for == #432

Open JorgeCepeda opened 1 year ago

JorgeCepeda commented 1 year ago

Like in some languages like Rust, make == compare by value using equals() if configured to do so, while maintaining some way of comparing pointer equality

CC007 commented 1 year ago

Maybe introduce the eq, ~==, ~= or #= or something similar for equals()? I think a lot of code would break if you replaced all == with equals()

Alternatively, <value> eq could create a predicate and <value> eq <otherValue> would test that predicate. So <value> eq would be compiled to otherVal -> <value>.equals(otherVal) and <value> eq <otherValue> would become (<value> eq).test(<otherValue>) which is otherVal -> <value>.equals(otherVal).test(<otherValue>)

JorgeCepeda commented 1 year ago

Could you explain it differently? I got lost in the third paragraph. Maybe this == behaviour could be opt-in per file or something?

CC007 commented 1 year ago

I was just thinking of how it could be implemented in a way that java understands it, because at the end of the day, all these manifold features are just syntactical sugar that needs to be compiled down to java.