在朱莉娅的可变结构的构造函数中的字典

Yas*_*ava 3 julia

是否可以用变量dict初始化一个可变结构.我正在尝试以下方法:

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
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我收到以下错误:

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

任何帮助是极大的赞赏.我正在使用Julia v 1.0

Bog*_*ski 8

你的dict的正确类型签名是:

Dict{Tuple{Int64,Int64},Int64}
Run Code Online (Sandbox Code Playgroud)

了解Julia中类型签名的最简单方法是创建所需类型的对象并使用typeof函数显示其类型:

julia> typeof(Dict((1,2)=>3))
Dict{Tuple{Int64,Int64},Int64}
Run Code Online (Sandbox Code Playgroud)