Oh. I haven't been able to find something in the manual saying that
collections are copied when variable types don't match.
Here is something closer to what I did, where it's less obvious what's
going on:
function f7()
d2::Dict{Int64,Int64}
d1 = d2 = Dict()
is(d1, d2)
end
julia> f7()
false
I'm used to languages where
x = y = z()
is equivalent to
y = z()
x = y
But:
function f8()
d2::Dict{Int64,Int64}
d2 = Dict()
d1 = d2
is(d1, d2)
end
julia> f8()
true
Perhaps the type inference is coming up with a different type for d1 in f8
vs. f7, so f7 copies but f8 does not.
function f9()
d1::Dict{Any,Any}
d2::Dict{Int64,Int64}
d2 = Dict()
d1 = d2
is(d1,d2)
end
julia> f9()
false
Are the subtleties of copying conversions and type inference documented
anywhere?
On Friday, May 6, 2016 at 9:53:22 AM UTC-7, Steven G. Johnson wrote:
>
> On Friday, May 6, 2016 at 12:48:20 PM UTC-4, David Dill wrote:
>>
>> function f4()
>> d1::Dict{Any,Any}
>> d2::Dict{Int64,Int64}
>> d1 = d2 = Dict()
>> is(d1, d2)
>> end
>>
>
> You are forcing a conversion from one type of Dict to another, which makes
> a copy.
>