2017-04-07 10 views
3

그래서 두 경우 사이의 결정적인 차이점은 무엇입니까형식 오류의 typeassert는

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 Vector{T} Array{T,1}있는 그대로를 따르고 다음과 같은 동작을

a = [1,2,3] 
a::Vector # works 

d = Dict(0=>a) 
typealias DictVector{K,V} Dict{K, Vector{V}} 
d::DictVector # fails 

오류를 이해하지 못하는 ?

모든 설명은 매우 복잡합니다.

답변

4

맞습니다. 이것은 0.5에있는 구형 시스템의 버그였습니다. 곧 출시 될 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 
+0

감사 명확히 대한 많은. 나는 이것이 일하기로되어서 기쁘다. – schlichtanders