Setdiff doesn't work


#1
julia> struct XX
           x::Int
           y::Float64
       end

julia> a = [XX(1,2.1),XX(2,3.1),XX(3,4.2)]
3-element Array{XX,1}:
 XX(1, 2.1)
 XX(2, 3.1)
 XX(3, 4.2)

julia> b = [XX(1,2.2),XX(2,3.2),XX(3,4.3)]
3-element Array{XX,1}:
 XX(1, 2.2)
 XX(2, 3.2)
 XX(3, 4.3)

function diff_fields(a::Vector{XX},b::Vector{XX})
                    Base.:(==)(x::XX,y::XX)= x.x == y.x
                    setdiff(a,b)
              end
diff_fields (generic function with 1 method)

julia> diff_fields(a,b)
2-element Array{XX,1}:
 XX(1, 2.1)
 XX(2, 3.1)

It should have returned [], but it didn’t. what is going wrong here?
Thanks


#2

You need to define a corresponding hash function.