-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parametrized typealias inconsistently creates subtype relation #8625
Comments
Expanding these out may help understand the question some: julia> ArToken{Int}
Token{Array{Int64,1}} (constructor with 1 method)
julia> ArToken
Token{Array{T,1}}
julia> Vector{Float64}
Array{Float64,1}
julia> Vector
Array{T,1} Which means that you're testing julia> Token{Array{Int64,1}} <: Token{Vector} # === Token{Array{T,1}}
false
julia> Array{Float64,1} <: Vector # === Array{T,1}
true Julia does not match tokens or type slots beyond the first level, which is probably why these don't work. Indeed, if we only try to match at the first level:
Unfortunately, that doesn't help when you want to specialize on I haven't explored this much, but one way around this might be by using the trick described in #2345 (comment). Cc: @timholy |
I've probably gone through this a half-dozen times, but keep forgetting and having to rediscover the answer. So for the record: julia> typealias CVec1{T<:Real} Vector{Complex{T}}
Array{Complex{T<:Real},1}
julia> typealias CVec2{C<:Complex} Vector{C}
Array{C<:Complex{T<:Real},1}
julia> typealias CVec3{T<:Real} CVec2{Complex{T}}
Array{Complex{T<:Real},1}
julia> typealias CVec4{T<:Real,C<:Complex} Union{Vector{C},Vector{Complex{T}}}
Union{Array{C<:Complex{T<:Real},1},Array{Complex{T<:Real},1}}
julia> typealias CVec5{T<:Real} CVec4{T,Complex{T}}
Union{Array{Complex{T<:Real},1},Array{Complex{T<:Real},1}}
julia> v = [2.0+3.0im]
1-element Array{Complex{Float64},1}:
2.0+3.0im
julia> isa(v, CVec1)
false
julia> isa(v, CVec1{Float64})
true
julia> isa(v, CVec2)
true
julia> isa(v, CVec3)
false
julia> isa(v, CVec3{Float64})
true
julia> isa(v, CVec4)
true
julia> isa(v, CVec5)
false I never seem to stop hoping that |
Tim, After I made my original posting, I figured out what was going on here, and in fact, I composed some text for the Julia manual: (begin quote) However, it is not always the case that a parametric typealias statement creates such a relation; for example, the statement: typealias AA{T} Array{Array{T,1},1} does not create the relation AA{Int} <: AA. The reason is that Array{Array{T,1},1} is not an abstract type at all; in fact, it is a concrete type describing a 1-dimensional array in which each entry is an object of type Array{T,1} for some value of T. (end quote) But meanwhile, in testing this, I just discovered a bug in 0.4.0-rc1: observe that 'show' for arrays is not working correctly in the following example: julia> typealias CVec1{T<:Real} Vector{Complex{T}}
Array{Complex{T<:Real},1}
julia> a1 = CVec1()
0-element Array{Complex{T<:Real},1}
julia> f = 6.3
6.3
julia> f2 = Float32(f)
6.3f0
julia> push!(a1,Complex(f,f))
1-element Array{Complex{T<:Real},1}:
6.3+6.3im
julia> push!(a1,Complex(f2,f2))
2-element Array{Complex{T<:Real},1}:
6.3+6.3im
6.3+6.3im
julia> a1[2]
6.3f0 + 6.3f0im Should I open a bug report? |
That's just julia> show(6.3f0)
6.3f0
julia> showcompact(6.3f0)
6.3 which is fine. |
closed by #18457 |
If a parametrized type is created by typealias, is it a subtype of the unparametrized type? Here is an example showing that Julia is inconsistent about this question. If I run this in the latest dev version of Julia, the first println yields "false" whereas the second yields "true". By the way, I don't know what the 'correct' answer is to the question.
kms Edit: formatting
The text was updated successfully, but these errors were encountered: