Stream: helpdesk (published)

Topic: upgrade type parameter to union supertype


view this post on Zulip cschen (Nov 19 2025 at 23:08):

Say I have something like this

const BigUnion = Union{Int, Float32}
struct Wrapper{S}
    a::S
end

w = Wrapper(3)::Wrapper{Int} # just for clarity

Is there an efficient way to "upgrate" w to a Wrapper{BigUnion}instead?
I've been rebuilding the whole object like:

w_union = Wrapper{BigUnion}(w.a)

but I'm curious to know if there is another way

view this post on Zulip Mason Protter (Nov 19 2025 at 23:23):

No, there's not really another way to re-parameterize types other than manually defining what you mean

view this post on Zulip Mason Protter (Nov 19 2025 at 23:23):

But what you're doing here should be efficient


Last updated: Nov 27 2025 at 04:44 UTC