Take this minimal example:

julia> k = ["a", "b"]
2-element Array{ASCIIString,1}:
 "a"
 "b"

julia> v = [1, 0.5]
2-element Array{Float64,1}:
 1.0
 0.5

julia> # This is expected
julia> Dict(k,v)
Dict{ASCIIString,Float64} with 2 entries:
  "b" => 0.5
  "a" => 1.0

julia> # But here the values are of type Any, not Float64
julia> ["a"=>1, "b"=>0.5]
Dict{ASCIIString,Any} with 2 entries:
  "b" => 0.5
  "a" => 1

It seems that the literal definition of dictionaries infers "Any" when the
values (or keys) are not of the same type -- in this example, an integer
and a float. In the creation of arrays, for instance, Julia is not that
loose (it infers Float64 in this example).

It happens the same with other types and supertypes, e.g. with ASCIIString
and UTF8String.

I would have expected the same behaviour in both ways of defining the
dictionary. Is there a reason why it is not so?

Regards
Helios

Reply via email to