Equals Problem


#1
julia> struct Field
           name::Symbol
           typ::Type
           Field(name::Symbol,typ::Symbol) = new(name,eval(typ))
       end

julia> #no need to check the type! closest
       function Base.broadcast(::typeof(==),f1::Field,f2::Field)
           isequal(f1.name,f2.name)
       end

julia> Base.hash(f::Field, h::UInt) = hash(f.name, hash(Field,h))

julia> f1 = Field(:a,:Int)
Field(:a, Int64)

julia> f2 = Field(:a,:Float64)
Field(:a, Float64)

julia> f1 == f2
false

I don’t understand what is going wrong, Can someone help me out?
Thanks


#2

Why did you define this function? Define Base.:(==)(::Field, ::Field) instead.


#3
WARNING: deprecated syntax "function .==(...)".
Use "function Base.broadcast(::typeof(==), ...)" instead.
ERROR: syntax: "(f1::Field,f2::Field)" is not a valid function argument name

Because of this warning, however i see Base.:(==) works, what is the difference between Base.== and Base.:(==)?

Thanks


#4

Oh, yeah that is a bit confusing.

.== is elementwise equals to:

julia> [1,2,3] .== [1,2,4]
3-element BitArray{1}:
 true
 true
 false

julia> [1,2,3] == [1,2,4]
false