# Question on composite types

**URL:** https://discourse.julialang.org/t/question-on-composite-types/43661
**Category:** New to Julia
**Tags:** question
**Created:** [July 25, 2020, 11:26am UTC](https://discourse.julialang.org/t/question-on-composite-types/43661 "2020-07-25T11:26:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)
#### Post date: [July 25, 2020, 11:26am UTC](https://discourse.julialang.org/t/question-on-composite-types/43661/1 "2020-07-25T11:26:46Z")

</div>

Is there a method that returns

```julia
Float64

```

if given the composite type

```julia
Point{Float64}

```

?  
is

---

<div class="post-metadata">

### Author: ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)
#### Post date: [July 25, 2020, 11:55am UTC](https://discourse.julialang.org/t/question-on-composite-types/43661/2 "2020-07-25T11:55:02Z")

</div>

You can get the parameters of a concrete type with:

```julia
julia> Vector{Int}.parameters
svec(Int64, 1)

```

---

<div class="post-metadata">

### Author: ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)
#### Post date: [July 25, 2020, 12:02pm UTC](https://discourse.julialang.org/t/question-on-composite-types/43661/3 "2020-07-25T12:02:41Z")

</div>

If you want to start from an instance, then a simple function can be used to extract it:

```julia
julia> struct Point{T}
       a::T
       end

julia> p=Point{Int}(42)
Point{Int64}(42)

julia> pointparam(::Point{T}) where T = T
pointparam (generic function with 1 method)

julia> pointparam(p)
Int64

```

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 25, 2020, 3:20pm UTC](https://discourse.julialang.org/t/question-on-composite-types/43661/4 "2020-07-25T15:20:06Z")

</div>

This is what `eltype` is usually used for. It doesn’t come for free for custom structs, so if it is your struct you need to do

```julia
Base.eltype(::Point{T}) where {T} = T

```

which is the same function as the previous post but you are sticking to the common usage here.

If you are using someone else’s package (or base Julia types), `eltype` should already be defined.

---

<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: [July 25, 2020, 5:45pm UTC](https://discourse.julialang.org/t/question-on-composite-types/43661/5 "2020-07-25T17:45:59Z")

</div>

> [@tbeason](#):
>
> This is what `eltype` is usually used for.

For iterables, yes, but that may not be the case here.

> [@tbeason](#):
>
> If you are using someone else’s package (or base Julia types), `eltype` should already be defined.

`eltype` has a catch-all method that falls back to `Any`, so in a sense it is always defined. However, it is only required to be correctly implemented if the relevant parts of the [iterator interface](https://docs.julialang.org/en/v1/manual/interfaces/) apply.
