If you make the Pair immutable then it should work out of the box.
(Note that Pair is a datatype in 0.4, so probably you should either use
something compatible or something else).

Immutables are compared by the value of their fields, whereas mutables
by ===, i.e. whether they are same object in memory.  Should be in the
docs.

But you can overload == to do what you want:

julia> type Pair
            a::Int
            b::Int
        end

julia> ==(a::Pair, b::Pair) = a.a==b.a && a.b==b.b
== (generic function with 80 methods)

julia> Pair(3,4)==Pair(3,4)
true


On Sat, 2015-04-18 at 09:29, Kuba Roth <[email protected]> wrote:
> Hi there,
> How do I make my custom type instance equal in Julia. 
> Why two instances with identical values on each field return me 'false' in 
> this case?
> Thank you.
>
> type Pair
>     a::Int
>     b::Int
> end
>
> x = Pair(1,2)
> y = Pair(1,2)
>
> println (x==y)    # returns false

Reply via email to