Dictionary in constructor for a mutable struct in Julia

Viewed 437

Is it possible to initialize a mutable struct with a variable which is a dict.I am trying the following:

mutable struct Global
    speciesCnt::Int64
    chromosomeCnt::Int64
    nodeCnt::Int64
    innov_number::Int64
    innovations::Dict{(Int64,Int64),Int64}
    cf::Config
    function Global(cf::Config)
        new(0,0,0,0,Dict{(Int64,Int64),Int64}(),cf) # global dictionary
    end
end

however, when I run it I get the following error:

LoadError: TypeError: in Type, in parameter, expected Type, got Tuple{DataType,DataType}.

Any help is greatly appreciated. I am using Julia v 1.0

1 Answers

A proper type signature for your dict is:

Dict{Tuple{Int64,Int64},Int64}

The easiest way to learn how type signatures in Julia look like is to create an object of the desired type and use typeof function to display its type:

julia> typeof(Dict((1,2)=>3))
Dict{Tuple{Int64,Int64},Int64}
Related