Some advice, please. Consider a structure like this:
immutable Foo
x::Int
y::Int
s::String
end
(In the past, this type didn’t have s
so ==
just compared x
and y
.)
I’d still like to have ==
compare x
and y
, but ignore s
. Because Foo
is immutable, ===
will compare all fields (which is useful as well). I was hoping to override ==
as follows:
== (a::Foo, b::Foo) = (a.x == b.x && a.y == b.y)
This way, Foo(1,2,"foo") == Foo(1,2,"bar")
is true
, but Foo(1,2,"foo") === Foo(1,2,"bar")
is false
.
Are there any unintended consequences to overriding ==
like this? (I am not doing anything with hashcodes or anything.)