# What are valid type parameters?

**URL:** https://discourse.julialang.org/t/what-are-valid-type-parameters/471
**Category:** General Usage
**Tags:** question
**Created:** [November 21, 2016, 2:33pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471 "2016-11-21T14:33:59Z")
**Posts on this page:** 6
**Page:** 1

<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: [November 21, 2016, 2:33pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/1 "2016-11-21T14:33:59Z")

</div>

I am trying to stuff quite a bit of information into parameters of a type, in the hope that dispatching on this will create efficient code. Doing this, I ran into the question of what is allowed, exactly.

Is the following correct: a value `V` is valid for a type parameter iff either

1. `isbits(V)`
2. `isa(V, Symbol)`
3. `isa(V, Type)`  
Is there anything else?

To make things concrete, what I am trying to encode as type parameters are a return type, and a `Vector{Pair{Int,Type}}`. The latter does not work, but I can split the pairs, ending up two vectors, which works.

---

<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 21, 2016, 2:52pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/2 "2016-11-21T14:52:16Z")

</div>

Also `Tuple` of `Symbol` and `isbits` type.

Encode return type in parameter is fine (like `convert`) but you shouldn’t try to “help” inference this way.

---

<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: [November 21, 2016, 3:00pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/3 "2016-11-21T15:00:04Z")

</div>

Thanks. I am not “helping” type inference, I am encoding all the information in type parameters (it does not exist anywhere else). I got the idea from a code example which converts parser spec strings to symbols, and puts them in a type parameter (can’t find the link now).

Another question I ran into is the following: given a `Tuple{...}`, how do I extract the type parameters? Eg from `Tuple{Int,Float64}`, how would I get the `[Int,Float64]`?

EDIT:

```julia
xx(T::Type) = map(name->fieldtype(T,name), fieldnames(T))

```

works. But I have a feeling I probably should not be doing this 😃

---

<div class="post-metadata">

### Author: ![akis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akis/32/156_2.png) [@akis](https://discourse.julialang.org/u/akis)
#### Post date: [November 21, 2016, 3:11pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/4 "2016-11-21T15:11:20Z")

</div>

> [@Tamas\_Papp](#):
>
> Another question I ran into is the following: given a Tuple{…}, how do I extract the type parameters? Eg from Tuple{Int,Float64}, how would I get the [Int,Float64]?

```julia
julia> [Tuple{Int,Float64}.parameters...]
2-element Array{DataType,1}:
 Int64
 Float64

```

---

<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: [November 21, 2016, 3:17pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/5 "2016-11-21T15:17:10Z")

</div>

> [@akis](#):
>
> ```julia
> [Tuple{Int,Float64}.parameters...]
> 
> ```

neat. another question: how could I have discovered this? I could not find it in the manual, and `dump` does not give anything meaningful for `Tuple`s.

---

<div class="post-metadata">

### Author: ![akis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akis/32/156_2.png) [@akis](https://discourse.julialang.org/u/akis)
#### Post date: [November 21, 2016, 3:20pm UTC](https://discourse.julialang.org/t/what-are-valid-type-parameters/471/6 "2016-11-21T15:20:24Z")

</div>

> [@Tamas\_Papp](#):
>
> how could I have discovered this?

```julia
julia> typeof(Tuple{Int,Float64})
DataType

julia> fieldnames(DataType)
17-element Array{Symbol,1}:
[...]
:parameters
[...]

```
