# What does Dict{T} mean?

**URL:** <https://discourse.julialang.org/t/what-does-dict-t-mean/69455>\
**Category:** General Usage\
**Tags:** dictionaries\
**Created:** [October 8, 2021, 9:35pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455 "2021-10-08T21:35:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 8, 2021, 9:35pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455/1 "2021-10-08T21:35:04Z")

</div>

Hi!

Here is the tiny project I have in mind so that I get my hands a bit dirty. I would like to extend the functionality of `StatsBase.countmap()` so that is accepts the `Dictionary` type aside from the `Dict` inbuilt data type.  
Going to `StatsBase.jl/src/count.jl` to see how `StatsBase.countmap()` is implemented I saw that it was based on the addcounts!() function. Here is its definition.

```julia
function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) where {T,W<:Real}
    n = length(x)
    length(wv) == n || throw(DimensionMismatch())
    w = values(wv)
    z = zero(W)

    for i = 1 : n
        @inbounds xi = x[i]
        @inbounds wi = w[i]
        cm[xi] = get(cm, xi, z) + wi
    end
    return cm
end

```

Now, my question is this: How is it possible to have `Dict{T}` in there that includes a single type for a dictionary within the curly braces? I am trying to find similar code or an explanation of why and how that is ok in Julia docu, but I had not luck. I know it may be a naive question, but I am stuck. Any short explanation/hint/direction would be greatly appreciated.

Thanks!

Alex

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [October 8, 2021, 9:41pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455/2 "2021-10-08T21:41:04Z")

</div>

Any unspecified type parameters are unconstrained, so it is an abstract type that includes any kind of `Dict` where the key type is `T`. Or put another way, `Dict{K}` means the same thing as `Dict{K, V} where V`. This method signature will only match if the key type of `cm` is the same as the element type of `x`. The value type of `cm` can be anything.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 8, 2021, 9:51pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455/3 "2021-10-08T21:51:45Z")

</div>

```julia
julia> function print_param(d::Dict{T}) where T
           display(T)
       end
print_param (generic function with 1 method)

julia> print_param(Dict(1=>"hi"))
Int64

```

Type parameters get filled in from left to right.

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 8, 2021, 10:06pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455/4 "2021-10-08T22:06:25Z")

</div>

Aha! Very interesting…So, the key type T is unconstrained but, at the same time, it is also minimally constrained by the element type of `x`.  
PS: Having this kind of unconstrained types can be really powerful when writing typed grammars for natural language.

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 8, 2021, 10:07pm UTC](https://discourse.julialang.org/t/what-does-dict-t-mean/69455/5 "2021-10-08T22:07:54Z")

</div>

Thanks for the code example @Oscar_Smith ! Really useful to get the hang of it!
