# Why is d::Dict !== Dict(d)?

**URL:** https://discourse.julialang.org/t/why-is-d-dict-dict-d/5197
**Category:** Internals & Design
**Created:** [August 3, 2017, 1:00am UTC](https://discourse.julialang.org/t/why-is-d-dict-dict-d/5197 "2017-08-03T01:00:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![garborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garborg/32/11446_2.png) [@garborg](https://discourse.julialang.org/u/garborg)
#### Post date: [August 3, 2017, 1:00am UTC](https://discourse.julialang.org/t/why-is-d-dict-dict-d/5197/1 "2017-08-03T01:00:54Z")

</div>

Does `Dict(::Dict)` copy only because the method is the vehicle for implementing `copy(d::Dict)`?

Fallback for `T(::T)`:

```nohighlight
(::Type{T})(arg) where {T} = convert(T, arg)::T # Hidden from the REPL.

```

usually leads to no copying:

```nohighlight
julia> x = "a"; x === typeof(x)(x)
true

julia> x = (1,"a"); x === typeof(x)(x)
true

julia> x = Ref("a"); x === Ref(x)
true

julia> x = ["a"]; x === typeof(x)(x)
true

julia> x = Dict(1 => "a"); x === typeof(x)(x)
false

```

I’m having trouble drawing a distinction.

Dict(d::Dict) behavior originally implemented [here](https://github.com/JuliaLang/julia/commit/41f3cf8fd176b92e1b49d89a84e1b495c8889bf1#diff-d4736682004c1996e5d9b1c5c33c8c8eR344).

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [August 3, 2017, 8:58am UTC](https://discourse.julialang.org/t/why-is-d-dict-dict-d/5197/2 "2017-08-03T08:58:37Z")

</div>

Looking at the code, what’s particularly weird is that the input dict is rehashed in place, and a copy of it is only taken after that. So copying isn’t even justified by the goal of not mutating the input dict

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 3, 2017, 9:49am UTC](https://discourse.julialang.org/t/why-is-d-dict-dict-d/5197/3 "2017-08-03T09:49:43Z")

</div>

Just having `Dict(::Dict)` copy seems weird to me. I opened an issue to track this: [https://github.com/JuliaLang/julia/issues/23107](https://github.com/JuliaLang/julia/issues/23107)
