Julia 自定义typealias的TypeError typeassert
我不理解以下行为Julia 自定义typealias的TypeError typeassert,julia,type-alias,Julia,Type Alias,我不理解以下行为 a = [1,2,3] a::Vector # works d = Dict(0=>a) typealias DictVector{K,V} Dict{K, Vector{V}} d::DictVector # fails 错误如下所示 TypeError: typeassert: expected Dict{K,Array{V,1}}, got Dict{Int64,Array{Int64,1}} in include_string(::String,
a = [1,2,3]
a::Vector # works
d = Dict(0=>a)
typealias DictVector{K,V} Dict{K, Vector{V}}
d::DictVector # fails
错误如下所示
TypeError: typeassert: expected Dict{K,Array{V,1}}, got
Dict{Int64,Array{Int64,1}}
in include_string(::String, ::String) at loading.jl:441
in eval(::Module, ::Any) at boot.jl:234
in (::Atom.##65#68)() at eval.jl:40
in withpath(::Atom.##65#68, ::Void) at utils.jl:30
in withpath(::Function, ::Void) at eval.jl:46
in macro expansion at eval.jl:109 [inlined]
in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60
然而,向量本身就是typealias向量{T}数组{T,1}
,那么这两种情况之间的决定性区别是什么
任何澄清都是高度赞赏的你说得对,应该是可行的。看起来这是0.5中旧类型系统中的一个bug。它在即将发布的0.6版本中得到了修复 以下是0.5的一个可能解决方案:
julia> typealias DictVector{K,V<:Vector} Dict{K,V}
Dict{K,V<:Array{T,1}}
julia> d::DictVector
Dict{Int64,Array{Int64,1}} with 1 entry:
0 => [1,2,3]
julia> isa(d, DictVector)
true
julia>typealias向量{K,V[1,2,3]
julia>isa(d,向量)
真的
非常感谢您的澄清。我很高兴这本应该有效