In Julia, composite types with at least one field that have the same hash values โโfor different values. This means that composite types do not work correctly if you use them as dictionary keys or anything else that depends on a hashed value. This behavior is incompatible with the behavior of other types, for example Vector {Int}.
More specific,
vectors of unconsolidated types that are different objects but have the same hash value with the same value:
julia> hash([1,2,3])==hash([1,2,3]) true
hash fieldless composite types with the same value:
julia> type A end julia> hash(A())==hash(A()) true
composite types with at least one field hash for different values, if they are different objects with the same value:
julia> type B b::Int end julia> hash(B(1))==hash(B(1)) false
however, the same object retains its hash even if the base values โโchange:
julia> b=B(1) julia> hash(b) 0x0b2c67452351ff52 julia> bb=2; julia> hash(b) 0x0b2c67452351ff52
this is incompatible with the behavior of vectors (if you change the item, hash changes):
julia> a = [1,2,3]; julia> hash(a) 0xd468fb40d24a17cf julia> a[1]=2; julia> hash(a) 0x777c61a790f5843f
this problem is missing for immutable types:
julia> immutable C c::Int end julia> hash(C(1))==hash(C(1)) true
Is there something fundamental that governs this behavior in terms of language design? Are there any plans to fix or fix this behavior?