Closed
Description
This might be a duplicate of #36377, not sure.
Suppose I want to make a type
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?
Metadata
Metadata
Assignees
Labels
No labels