It seems dictionaries uses identity instead of equality, to determine the 
uniqueness of the key:

ismaelvc@toybox ~> julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+1419 (2014-02-06 22:55 
UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit a673e4c* (1 days old master)
|__/                   |  i686-pc-linux-gnu

julia> Int # I'm on 32 bit version.
Int32

julia> d = Dict{Integer, Integer}()
Dict{Integer,Integer}()

julia> d[3] = 1
1

julia> d[convert(Int64, 3)] = 5
5

julia> for (key, val) in d
           println("The key: $(key), of type: $(typeof(key)), maps to: 
$(val)
Bits representation: $(bits(key))")
       end
The key: 3, of type: Int32, maps to: 1
Bits representation: 00000000000000000000000000000011
The key: 3, of type: Int64, maps to: 5
Bits representation: 
0000000000000000000000000000000000000000000000000000000000000011

julia> x, y = keys(d)
KeyIterator{Dict{Integer,Integer}}([3=>1,3=>5])

julia> x, typeof(x)
(3,Int32)

julia> y, typeof(y)
(3,Int64)

julia> x == y # Tests equality
true

julia> x === y # Tests identity 
false

julia> is(x, y) # Same as: x == y
false

julia> help(===)
Loading help data...
Base.is(x, y)

   Determine whether "x" and "y" are identical, in the sense that
   no program could distinguish them. Compares mutable objects by
   address in memory, and compares immutable objects (such as numbers)
   by contents at the bit level. This function is sometimes called
   "egal". The "===" operator is an alias for this function.

julia> d = Dict{Int64, Int32}()
Dict{Int64,Int32}()

julia> d[convert(Int64, 3)] = 5
5

julia> get(d, 3, 0) # Calling with the Int32 key:
0

julia> get(d, convert(Int64, 3), 0) # Needs to be the same Int64 type:
5



Reply via email to