# Parametric type that can "act" as its parameter type

**URL:** <https://discourse.julialang.org/t/parametric-type-that-can-act-as-its-parameter-type/39339>\
**Category:** General Usage\
**Created:** [May 12, 2020, 10:47am UTC](https://discourse.julialang.org/t/parametric-type-that-can-act-as-its-parameter-type/39339 "2020-05-12T10:47:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rlrs/32/18043_2.png) [@rlrs](https://discourse.julialang.org/u/rlrs)\
**Post date:** [May 12, 2020, 10:47am UTC](https://discourse.julialang.org/t/parametric-type-that-can-act-as-its-parameter-type/39339/1 "2020-05-12T10:47:39Z")

</div>

I’m trying to write a type, let’s call it `Hole{T}`, which can be assigned to a field of type `T` in a struct. Is this possible to do? I realize it might be quite weird type-wise, but if my other option is to rewrite all my struct fields to be `Union{T, Hole}`, this seems cleaner.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 12, 2020, 10:57am UTC](https://discourse.julialang.org/t/parametric-type-that-can-act-as-its-parameter-type/39339/2 "2020-05-12T10:57:12Z")

</div>

> [@rlrs](#):
>
> Is this possible to do?

Not when `T` is a concrete type.

> [@rlrs](#):
>
> my other option is to rewrite all my struct fields to be `Union{T, Hole}` , this seems cleaner.

I am not sure I understand why you think this. Your use case is precisely what `Union` is for. Just use a concrete type for both options, eg `Union{T,Hole{T}}`.

---

<div class="post-metadata">

**Author:** ![rlrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rlrs/32/18043_2.png) [@rlrs](https://discourse.julialang.org/u/rlrs)\
**Post date:** [May 12, 2020, 11:04am UTC](https://discourse.julialang.org/t/parametric-type-that-can-act-as-its-parameter-type/39339/3 "2020-05-12T11:04:20Z")

</div>

> [@Tamas\_Papp](#):
>
> I am not sure I understand why you think this. Your use case is precisely what `Union` is for. Just use a concrete type for both options, eg `Union{T,Hole{T}}` .

This is the situation: I have an abstract syntax tree, in a grammar I didn’t necessarily write myself. I want to represent partial, typed trees, by replacing expressions in the abstract syntax tree by `Hole`s. Since I didn’t write the AST representation, I would prefer to not modify it directly, but instead keep that definition separate from my partial syntax trees.
