# Behavior of ImmutableDict

**URL:** https://discourse.julialang.org/t/behavior-of-immutabledict/56107
**Category:** General Usage
**Created:** [February 26, 2021, 6:11pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107 "2021-02-26T18:11:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)
#### Post date: [February 26, 2021, 6:11pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107/1 "2021-02-26T18:11:47Z")

</div>

Can anyone explain why `ImmutableDict` works the way it does?

I can’t specify the type when declaring it:

```julia
# Produces MethodError.
weapons = ImmutableDict{String,Int32}("Light-Rifle" => 100, "Plasma-Pistol" => 50)

```

I can’t pass in an array of pairs:

```julia
weapon_pairs = Pair{String,Int32}[("Light-Rifle" => 100),("Plasma Pistol" => 50)]
# Produces MethodError.
weapons = ImmutableDict(weapon_pairs)

```

It’s considered an `AbstractDict`:

```julia
println(isa(weapons,AbstractDict)) # true

```

Why can’t I specify the `KV` types or pass in an array of pairs?

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [February 26, 2021, 7:10pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107/2 "2021-02-26T19:10:50Z")

</div>

`ImmutableDict` has a limited and convoluted way to add elements:

```julia
julia> import Base: ImmutableDict

julia> weapons = ImmutableDict{String,Int32}("Light-Rifle", 100)
ImmutableDict{String, Int32} with 1 entry:
  "Light-Rifle" => 100

julia> weapons = ImmutableDict{String,Int32}(weapons, "Plasma Pistol", 50)
ImmutableDict{String, Int32} with 2 entries:
  "Plasma Pistol" => 50
  "Light-Rifle" => 100

```

Probably there are very few users of this type (it isn’t even exported) that no one got around making its usage more comfortable

---

<div class="post-metadata">

### Author: ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)
#### Post date: [February 26, 2021, 8:11pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107/3 "2021-02-26T20:11:09Z")

</div>

The funny part is that it’s in the documentation, so I decided to try it out for myself.

When you say hasn’t been exported, you mean, I can’t use it naturally, I have to `import` from `Base` before using, correct?

---

<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: [February 26, 2021, 8:47pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107/4 "2021-02-26T20:47:24Z")

</div>

I don’t think `ImmutableDict` is intended to be used outside of Base. Where did you find out about it?

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [February 26, 2021, 11:59pm UTC](https://discourse.julialang.org/t/behavior-of-immutabledict/56107/5 "2021-02-26T23:59:29Z")

</div>

(I use it outside of `Base` 👀 well, I reimplemented it to not do type piracy)
