Because of the issues with the default definition of
==, I often find myself having to define
== to be extra safe. It would be nice if writing the function were really simple, I’d like to do
typeof(t1) == typeof(t2) || (return false) all(getfield(t1, i) == getfield(t2, i) for i ∈ 1:nfields(t1))
Now, initially I would have thought that I can’t do this, because the compiler would not know ahead of time what all the types of the fields would be and I’d get lousy performance. However, I ran
@code_warntype on this and lo and behold it looks completely type stable.
Can I trust this in the general case? It seems a little too magical.