How do a I get a type "stripped" of parameters?

struct Foo{T} end

What function takes Foo{Int} and returns the parent UnionAll type, Foo?

julia> a


Thanks, but I was wondering if there is something in the public API to do this. Or is this stable? ( used to have different behaviour, if I recall correctly)

no and no, the objective you’re after is “hacky” to begin with

Can you elaborate on why my query is ill-defined? Are you suggesting that there may be no least upper bound for a concrete type with parameters, among all UnionAll types? Or that there could be more than one?

the “wrapper type without parametric types” information is not captured by Julia’s typing system:

julia> f(x::T{Int64}) where T = T

Attempts to grab it will be fully dynamic. Possible solutions include what I described (which should be semi-stable tbh), or eval()ing the names, pick your poison


doesn’t look too bad actually

1 Like

I think eval(nameof(Foo{T} where T)) does what you’re looking for, but it’s not type-stable.

julia> struct Foo{T} end

julia> eval(nameof(Foo{Int}))

This is the solution that was alluded to above, but recommended against.


Great. In my use case performance is not important.

Also see ConstructionBase.jl/ConstructionBase.jl at master · JuliaObjects/ConstructionBase.jl · GitHub and it’s note ConstructionBase.jl/ at master · JuliaObjects/ConstructionBase.jl · GitHub. I think that does what you want.

1 Like

There is another option:

basetype(::Type{T}) where T = Base.typename(T).wrapper

from Export typename(x).wrapper as a Base function · Issue #39952 · JuliaLang/julia · GitHub