# Best way to declare parametric types of parametric types

**URL:** <https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237>\
**Category:** New to Julia\
**Tags:** question, parametric-types\
**Created:** [June 12, 2023, 4:09pm UTC](https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237 "2023-06-12T16:09:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![70Gage70](https://avatars.discourse-cdn.com/v4/letter/7/e68b1a/32.png) [@70Gage70](https://discourse.julialang.org/u/70Gage70)\
**Post date:** [June 12, 2023, 4:09pm UTC](https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237/1 "2023-06-12T16:09:32Z")

</div>

Suppose I have a type, let’s say

```julia
struct MyPoint{T<:AbstractFloat}
    x::T
    y::T
end

```

My understanding is that this is the best way to declare parametric types as per the Julia performance tips. But suppose you have another type that depends on `MyPoint`.

```julia
struct MyVector{T<:AbstractFloat}
    p1::MyPoint{T}
    p2::MyPoint{T}
    some_parameter::T
end

```

Is this how that should be done? Or some other way? Should I define `abstract type AbstractPoint end` , then make `MyPoint` a subtype of `AbstractPoint` and then have

```julia
struct MyVector{P<:AbstractPoint, T<:AbstractFloat}
    p1::P
    p2::P
    some_parameter::T
end

```

Is there any reason to do that if `MyPoint` would be the only subtype of `AbstractPoint`?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 12, 2023, 4:53pm UTC](https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237/2 "2023-06-12T16:53:34Z")

</div>

You can do either in this case, yes. They are the same, with the only difference being that `P` is less restricted in the second case, should some new subtype for `AbstractPoint` be created.

---

<div class="post-metadata">

**Author:** ![70Gage70](https://avatars.discourse-cdn.com/v4/letter/7/e68b1a/32.png) [@70Gage70](https://discourse.julialang.org/u/70Gage70)\
**Post date:** [June 12, 2023, 5:08pm UTC](https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237/3 "2023-06-12T17:08:03Z")

</div>

Great, thanks!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 12, 2023, 5:10pm UTC](https://discourse.julialang.org/t/best-way-to-declare-parametric-types-of-parametric-types/100237/4 "2023-06-12T17:10:04Z")

</div>

Not only `AbstractPoint` allows for people to create new subtypes and use them, but also does _not_ guarantee that the `AbstractPoint` stores values of type `T` inside it. I do not believe they will have similar performance, the first option will probably always have the best performance.
