# How to access the parameter list of a super type

**URL:** <https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739>\
**Category:** General Usage\
**Created:** [June 17, 2018, 10:55pm UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739 "2018-06-17T22:55:34Z")\
**Posts on this page:** 8\
**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:** [June 17, 2018, 10:55pm UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/1 "2018-06-17T22:55:34Z")

</div>

Hi fellows,

Here is what i want to do:

```nohighlight
abstract type DEF{super<:Tuple}

struct X <: DEF{Tuple{F,Y,Z{Int}}}

end

```

I want to access the supertype of X which is DEF  
and specifically what types are in the tuple Tuple{F,Y,Z{Int}}}  
F, Y and Z{Int} as types  
How can i do that?

Thanks.

---

<div class="post-metadata">

**Author:** ![Philip\_Stuckey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philip_stuckey/32/4000_2.png) [@Philip\_Stuckey](https://discourse.julialang.org/u/Philip_Stuckey)\
**Post date:** [June 18, 2018, 12:25am UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/2 "2018-06-18T00:25:17Z")

</div>

when creating a method that does something with variables of type `X` you need to include a `where` clause in the method signature so that Julia knows how to branch off different types. Here is a minimally working example:

```julia
abstract type DEF{Super <: Tuple}
end #even abstract type definitions need an end

#note the type parameters for X, they tell the compiler that F, Y, and Z are typevars and not existing types
struct X{F,Y, Z} <: DEF{Tuple{F, Y, Z} }
end

function does_something(x::X{F,Y, Z}) where {F, Y, Z}
    println("F is an $F, Y is a $Y, Z is a $Z") #use F, Y, and Z like any normal type
    z = Z() # a variable of type Z, assuming it has an appropriate constructor
end

```

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [June 18, 2018, 12:47am UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/3 "2018-06-18T00:47:04Z")

</div>

> [@Philip\_Stuckey](#):
>
> struct X{F,Y, Z} \<: DEF{Tuple{F, Y, Z} } end

The internal structure of type X is somewhat convoluted, but you can retrieve the individual type parameters as follows (Julia v0.6.2):

```julia
julia> X.var
F

julia> X.body.var
Y

julia> X.body.body.var
Z
```

---

<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:** [June 18, 2018, 5:18am UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/4 "2018-06-18T05:18:39Z")

</div>

These are implementation details, and accessing them is not good style (they may change without warning or deprecation).

Within functions, the approach suggested by @Philip_Stuckey above is best, but if the parameter is needed explicitly, it can be extracted with a function like

```julia
gimme_Z(::X{F,Y,Z}) where {F,Y,Z} = Z

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 18, 2018, 5:30am UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/5 "2018-06-18T05:30:01Z")

</div>

There is a section in the manual:

[https://docs.julialang.org/en/latest/manual/methods/#Design-Patterns-with-Parametric-Methods-1](https://docs.julialang.org/en/latest/manual/methods/#Design-Patterns-with-Parametric-Methods-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:** [June 19, 2018, 8:45pm UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/6 "2018-06-19T20:45:30Z")

</div>

But i wouldn’t know how many elements there are in the tuple at time.

What else can i do?

Thanks

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 19, 2018, 8:51pm UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/7 "2018-06-19T20:51:47Z")

</div>

Well, one could argue that you shouldn’t handle type parameters when you don’t know what they stand for. Translated to your problem: you should enumerate the different possibilities. Otherwise, does [post 3](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/3) not work?

---

<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:** [June 19, 2018, 9:14pm UTC](https://discourse.julialang.org/t/how-to-access-the-parameter-list-of-a-super-type/11739/8 "2018-06-19T21:14:51Z")

</div>

I guess the simplest answer would be put a threshold and use that much elements in the tuple as max.

Thanks
