# How to extract type parameters that are used as upper bounds in \`UnionAll\`?

**URL:** <https://discourse.julialang.org/t/how-to-extract-type-parameters-that-are-used-as-upper-bounds-in-unionall/117557>\
**Category:** General Usage\
**Tags:** type, parametric-types\
**Created:** [July 28, 2024, 1:57am UTC](https://discourse.julialang.org/t/how-to-extract-type-parameters-that-are-used-as-upper-bounds-in-unionall/117557 "2024-07-28T01:57:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [July 28, 2024, 7:30am UTC](https://discourse.julialang.org/t/how-to-extract-type-parameters-that-are-used-as-upper-bounds-in-unionall/117557/2 "2024-07-28T07:30:05Z")

</div>

I don’t think this is possible to achieve in a supported way. Some previous discussion:

> [@Is there a way to capture an upper bound via dispatch?](https://discourse.julialang.org/t/is-there-a-way-to-capture-an-upper-bound-via-dispatch/63718):
>
> As part of the logic of writing some function, I’d like to use the upper bound of some passed-in type’s argument. Is there any way to capture this upper bound cleanly via dispatch? Basically, I’d like the following: struct Foo{T\<:Real} end capture\_upper\_bound(Foo{Real}) # should return Real capture\_upper\_bound(Foo{\<:Real}) # should return Real capture\_upper\_bound(Foo{\<:Int}) # should return Int capture\_upper\_bound(Foo{\<:Number}) # should be a method error The following definition of c…

> [@Deconstructing UnionAll types](https://discourse.julialang.org/t/deconstructing-unionall-types/108328/):
>
> The following naive definition is invalid, but you don’t realize it until you try it: julia\> f(::Type{Set{\<:W}} where W) = W f (generic function with 4 methods) Here goes… julia\> f(Set{\<:Integer}) ERROR: UndefVarError: `W` not defined I can get the functionality I wanted with a hack: julia\> f\_hack(t::Type{Set{\<:W}} where W) = t.var.ub f\_hack (generic function with 1 method) julia\> f\_hack(Set{\<:Integer}) Integer So how do I do this with public API?

AFAIK, in Julia’s dispatch logic, a method static parameter must be uniquely determined, with it’s lower bound equal to its upper bound, to be defined in the method body. So “extracting an upper bound” seems like something that would require additional language features.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-extract-type-parameters-that-are-used-as-upper-bounds-in-unionall/117557)._
