2017-04-07 2 views
3

ich nicht das folgende VerhaltenTypeerror typeassert für benutzerdefinierte typealias

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

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

der Fehler wird die folgende

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 

jedoch Vektor selbst als typealias Vector{T} Array{T,1} so verstehen, was ist der entscheidende Unterschied zwischen den beiden Fällen ?

Jede Klarstellung ist sehr appriciated

Antwort

4

Du hast Recht, die funktionieren sollte. Es scheint, dass dies ein Fehler im alten System in 0,5 war. Es ist in der kommenden Version 0.6 behoben.

Hier ist eine mögliche Abhilfe für 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

vielen Dank für die Klärung. Ich bin froh, dass das funktionieren sollte – schlichtanders

Verwandte Themen