# How to recover the parameters of a parametric type?

**URL:** <https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108>\
**Category:** New to Julia\
**Tags:** parametric-types\
**Created:** [June 10, 2020, 1:45am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108 "2020-06-10T01:45:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Queiroz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_queiroz/32/12086_2.png) [@Lucas\_Queiroz](https://discourse.julialang.org/u/Lucas_Queiroz)\
**Post date:** [June 10, 2020, 1:45am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/1 "2020-06-10T01:45:46Z")

</div>

Is there any function that receives a parametric type as input and returns the parameters? For example, does the function below exist?

```julia
julia> get_parameters(Array{Float64, 2})
(Float64, 2)

```

In case `get_parameters` doesn’t exist, what are the alternatives?

I am asking this question because I am writing numerical algorithms with the fixed points of the [FixedPointNumbers.jl package](https://github.com/JuliaMath/FixedPointNumbers.jl). When my function `g()` receives a `Fixed{T,f}` number, it needs to know the parameters `T` and `f` because they will determine the accuracy of my algorithm.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 10, 2020, 1:52am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/2 "2020-06-10T01:52:25Z")

</div>

How about this?

```julia
get_T(::Fixed{T, f}) where {T, f} = T

get_f(::Fixed{T, f}) where {T, f} = f

```

Those functions expect to be passed a value of some `Fixed` type. If you want to pass the type itself, you can do:

```julia
get_T(::Type{Fixed{T, f}}) where {T, f} = T

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 10, 2020, 2:08am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/3 "2020-06-10T02:08:10Z")

</div>

`eltype()` ?

> **[eltype » Julia Functions](http://www.jlhub.com/julia/manual/en/function/eltype)**
>
> Learn Julia with our free tutorials and guides

---

<div class="post-metadata">

**Author:** ![Lucas\_Queiroz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_queiroz/32/12086_2.png) [@Lucas\_Queiroz](https://discourse.julialang.org/u/Lucas_Queiroz)\
**Post date:** [June 10, 2020, 2:16am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/4 "2020-06-10T02:16:05Z")

</div>

It worked, thanks!

---

<div class="post-metadata">

**Author:** ![Lucas\_Queiroz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_queiroz/32/12086_2.png) [@Lucas\_Queiroz](https://discourse.julialang.org/u/Lucas_Queiroz)\
**Post date:** [June 10, 2020, 2:17am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/5 "2020-06-10T02:17:28Z")

</div>

Thank you for helping me. I did not understand eltype behavior very well, I tried using it in the REPL

```julia
julia> x = Fixed{Int64, 51}(9.3)
9.3Q12f51

julia> eltype(x)
Fixed{Int64,51}

```

But I do not know how to use it to extract `Int64` and `51`.

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [June 10, 2020, 6:47am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/6 "2020-06-10T06:47:48Z")

</div>

```julia
julia> x = Fixed{Int64, 51}(9.3)
9.3Q12f51

julia> eltype(x)
Fixed{Int64,51}

julia> typeof(x.i)
Int64

```

I don’t think you can get `f` any easy way.

Oh, yes you can:

```julia
julia> x = Fixed{Int32, 13}(9.3)
9.3Q18f13

julia> z = Base.decompose(x)
(76186, -13, 1)
T = typeof(z[1])
f = -z[2]

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 10, 2020, 7:07am UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/7 "2020-06-10T07:07:52Z")

</div>

Sorry, I was typing from my mobile without proper testing. `eltype()` seems working only for containers-like parametric types, and any-how it returns only the type parameter (e.g. `eltype([1,2])` returns `Int64`).

---

<div class="post-metadata">

**Author:** ![Lucas\_Queiroz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_queiroz/32/12086_2.png) [@Lucas\_Queiroz](https://discourse.julialang.org/u/Lucas_Queiroz)\
**Post date:** [June 10, 2020, 2:57pm UTC](https://discourse.julialang.org/t/how-to-recover-the-parameters-of-a-parametric-type/41108/8 "2020-06-10T14:57:45Z")

</div>

Ok
