Skip to content

Make it easier to use "inner type parameters" in wrapper types. #38111

Closed
@jakobnissen

Description

@jakobnissen

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions