# Construct \`Union{T, U} where T\<:Integer where U\<:Float64\` from \`Union{TypeVar(:T, Integer), TypeVar(:U, Float64)}\`

**URL:** <https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [October 22, 2021, 5:15pm UTC](https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230 "2021-10-22T17:15:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdheepak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdheepak/32/10881_2.png) [@kdheepak](https://discourse.julialang.org/u/kdheepak)\
**Post date:** [October 22, 2021, 5:15pm UTC](https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230/1 "2021-10-22T17:15:17Z")

</div>

I’m trying to construct a type programmatically but failing to do so. The crux of my problem is that `UnionAll(TypeVar(:T, Integer), Union{TypeVar(:T, Integer), TypeVar(:U, Float64)})` doesn’t return a `UnionAll` type, and instead returns a `Union` . I’m wondering if this is intended or a bug in Julia? If it is intended, what is the recommended way to construct this specific `UnionAll`?

In the latest Julia nightly, this is what I get:

```julia
julia> UnionAll(TypeVar(:T, Integer), Union{TypeVar(:T, Integer), TypeVar(:U, Float64)}) Union{T<:Integer, U<:Float64}

```

I was expecting to get:

```julia
Union{T, U<:Float64} where T<:Integer

```

Here’s a screenshot of the Julia REPL where I was exploring the fields and the types of the various types involved:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/6/7666cab813efb44771e8ee75782fca21f47b16fa.png)

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [October 22, 2021, 5:26pm UTC](https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230/2 "2021-10-22T17:26:27Z")

</div>

```julia
julia> u = Union{TypeVar(:T, Integer), TypeVar(:U, Float64)}
Union{T<:Integer, U<:Float64}

julia> UnionAll(u.a, UnionAll(u.b, u))
Union{T, U} where {T<:Integer, U<:Float64}

```

Ref: [More about types · The Julia Language](https://docs.julialang.org/en/v1/devdocs/types/#UnionAll-types)

Edit: That said, yes, I kinda feel like

```julia
julia> u = Union{TypeVar(:T, Integer), TypeVar(:U, Float64)}
Union{T<:Integer, U<:Float64}

julia> u2 = Union{TypeVar(:T, Integer), TypeVar(:U, Float64)}
Union{T<:Integer, U<:Float64}

julia> UnionAll(u.a, u2)
Union{T<:Integer, U<:Float64}

julia> UnionAll(u.a, u)
Union{T, U<:Float64} where T<:Integer

```

is a bug.

---

<div class="post-metadata">

**Author:** ![kdheepak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdheepak/32/10881_2.png) [@kdheepak](https://discourse.julialang.org/u/kdheepak)\
**Post date:** [October 22, 2021, 5:38pm UTC](https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230/3 "2021-10-22T17:38:13Z")

</div>

Wow. So it has to be the same instance?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [October 22, 2021, 5:40pm UTC](https://discourse.julialang.org/t/construct-union-t-u-where-t-integer-where-u-float64-from-union-typevar-t-integer-typevar-u-float64/70230/4 "2021-10-22T17:40:20Z")

</div>

Yup. I suspect this happens because two instances of the “same” `TypeVar` aren’t ever equal/egal, but didn’t look at the implementation to check whether that’s actually the issue here.
