The easiest way is to let the Dict
constructor figure out the type for you by providing at least one key-value pair to the constructor:
julia> d = Dict(@view((@MVector [1,2,3,4,5])[1:2]) => 1)
Dict{SubArray{Int64, 1, MVector{5, Int64}, Tuple{UnitRange{Int64}}, true}, Int64} with 1 entry:
[1, 2] => 1
julia> d[@view((@MVector [1,2,3,4,5])[1:3])] = 2
2
julia> d
Dict{SubArray{Int64, 1, MVector{5, Int64}, Tuple{UnitRange{Int64}}, true}, Int64} with 2 entries:
[1, 2, 3] => 2
[1, 2] => 1
The other option is to use typeof
:
julia> T = typeof(@view((@MVector [1,2,3,4,5])[1:2]))
SubArray{Int64, 1, MVector{5, Int64}, Tuple{UnitRange{Int64}}, true}
julia> d = Dict{T, Int}()
Dict{SubArray{Int64, 1, MVector{5, Int64}, Tuple{UnitRange{Int64}}, true}, Int64}()
Generally you don’t want to try to write down complicated types like SubArray{Int64, 1, MVector{5, Int64}, Tuple{UnitRange{Int64}}, true}
by hand, especially if they are types that come from somebody else’s package. Also, in many cases, the exact details of a type signature are not part of the public API—they’re just implementation details.