# How to hack into type generation using UnionAlls?

**URL:** <https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976>\
**Category:** General Usage\
**Created:** [November 12, 2019, 12:27am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976 "2019-11-12T00:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 12, 2019, 12:27am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976/1 "2019-11-12T00:27:02Z")

</div>

```nohighlight
julia> abstract type Atype{Q} end

julia> Atype{Int}
Atype{Int64}

```

However I want Atype{Int} to produce Union{Atype{Int64}, Atype{Number}, Atype{Signed}}

So is there way that I can programmatically intervene in the generation of a type?  
Thanks

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [November 12, 2019, 12:50am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976/2 "2019-11-12T00:50:52Z")

</div>

```julia
Atype{<:Number}

```

?

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 12, 2019, 1:46am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976/3 "2019-11-12T01:46:12Z")

</div>

> [@Qiyamah](#):
>
> Union{Atype{Int64}, Atype{Number}, Atype{Signed}}

nice 🙂 But I want to go from Int → all 🙂 this was a specific example.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 12, 2019, 2:37am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976/4 "2019-11-12T02:37:58Z")

</div>

Core.apply\_type is called whenever a UnionAll is given parameters to be specialized. However we are not allowed to add a method to apply\_type function since it is a builtin. Is there a way to intercept apply\_type?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 12, 2019, 3:05am UTC](https://discourse.julialang.org/t/how-to-hack-into-type-generation-using-unionalls/30976/5 "2019-11-12T03:05:19Z")

</div>

No that’s not possible.

What do you want? If you just want a short syntax to generate types, use a function. If you want dispatch to work on it then no you are not allowed to do that.
