You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
struct Foo{I <: Integer}
v::Vector{Complex{I}}
end
Now, at runtime, I have a vector of integer Complex, but I don't know which integer type, so I can just make an abstractly typed array:
julia> v = Complex{<:Integer}[Complex{Int}(1, 1)]
1-element Array{Complex{var"#s16"} where var"#s16"<:Integer,1}:
1 + 1im
But now, how do I wrap v in a Foo?
julia> Foo{<:Integer}(v)
ERROR: MethodError: no method matching Foo{var"#s12"} where var"#s12"<:Integer(::Array{Complex{var"#s16"} where var"#s16"<:Integer,1})
One workaround is to instead define
struct Foo{C <: Complex{<:Integer}}
v::Vector{C}
end
But I think having Complex as part of Foo's signature is unnecessary. Would it be possible to enable the "direct" use of <:Integer in this case?
The text was updated successfully, but these errors were encountered:
Basically, no --- it's possible to define a constructor for Foo{<:Integer}(v), but that constructor would still have to return an instance of a concrete type, so it would still have to pick a specific value for I.
Ah, I see. So the reason for having to have the wrapper type Complex in Foo{C <: Complex{<:Integer}} is that Foo{<:Integer} is a UnionAll type whereas Foo{Complex{<:Integer}} is concrete.
This might be a duplicate of #36377, not sure.
Suppose I want to make a type
Now, at runtime, I have a vector of integer
Complex
, but I don't know which integer type, so I can just make an abstractly typed array:But now, how do I wrap
v
in aFoo
?One workaround is to instead define
But I think having
Complex
as part ofFoo
's signature is unnecessary. Would it be possible to enable the "direct" use of<:Integer
in this case?The text was updated successfully, but these errors were encountered: