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

**URL:** https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465
**Category:** General Usage
**Created:** [December 22, 2021, 1:37am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465 "2021-12-22T01:37:12Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [December 22, 2021, 1:37am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/1 "2021-12-22T01:37:12Z")

</div>

```julia
struct Foo{T} end

```

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

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 22, 2021, 1:46am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/2 "2021-12-22T01:46:18Z")

</div>

```julia
julia> a
Rational{Int64}

julia> a.name.wrapper
Rational

```

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [December 22, 2021, 2:12am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/3 "2021-12-22T02:12:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 22, 2021, 2:35am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/4 "2021-12-22T02:35:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [December 22, 2021, 2:42am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/5 "2021-12-22T02:42:40Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 22, 2021, 2:57am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/6 "2021-12-22T02:57:36Z")

</div>

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

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

```

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

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 22, 2021, 3:31am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/7 "2021-12-22T03:31:18Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/3/f/3fe6e8f03399d27f2c7fa562b482eb21922f104b.png)

doesn’t look too bad actually

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [December 22, 2021, 4:12am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/8 "2021-12-22T04:12:11Z")

</div>

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

```julia
julia> struct Foo{T} end

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

```

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

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [December 22, 2021, 4:48am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/9 "2021-12-22T04:48:01Z")

</div>

Great. In my use case performance is not important.

---

<div class="post-metadata">

### Author: ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)
#### Post date: [December 22, 2021, 11:20am UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/10 "2021-12-22T11:20:48Z")

</div>

Also see [https://github.com/JuliaObjects/ConstructionBase.jl/blob/master/src/ConstructionBase.jl#L27](https://github.com/JuliaObjects/ConstructionBase.jl/blob/master/src/ConstructionBase.jl#L27) and it’s note [https://github.com/JuliaObjects/ConstructionBase.jl/blob/master/src/constructorof.md](https://github.com/JuliaObjects/ConstructionBase.jl/blob/master/src/constructorof.md). I think that does what you want.

---

<div class="post-metadata">

### Author: ![denius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denius/32/3607_2.png) [@denius](https://discourse.julialang.org/u/denius)
#### Post date: [December 23, 2021, 6:15pm UTC](https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/11 "2021-12-23T18:15:47Z")

</div>

There is another option:

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

```

from [https://github.com/JuliaLang/julia/issues/39952](https://github.com/JuliaLang/julia/issues/39952)
