# Nested parametric type?

**URL:** <https://discourse.julialang.org/t/nested-parametric-type/58009>\
**Category:** New to Julia\
**Created:** [March 26, 2021, 11:24am UTC](https://discourse.julialang.org/t/nested-parametric-type/58009 "2021-03-26T11:24:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![huchiayu0517](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/huchiayu0517/32/8202_2.png) [@huchiayu0517](https://discourse.julialang.org/u/huchiayu0517)\
**Post date:** [March 26, 2021, 11:24am UTC](https://discourse.julialang.org/t/nested-parametric-type/58009/1 "2021-03-26T11:24:07Z")

</div>

I’m working on a tree code where I have defined the following types:

```julia
using StaticArrays

mutable struct Data{N,T}
	pos::SVector{N,T}
	mass::T
end

mutable struct Node{N,T}
    center::SVector{N,T}
	p::Union{Data{N,T}, Nothing}
	child::Union{Array{Node{N,T},1}, Nothing}
end

```

and I now want to change the definition of Node into

```julia
mutable struct Node{Data{N,T}}
    center::SVector{N,T}
	p::Union{Data{N,T}, Nothing}
	child::Union{Array{Node{N,T},1}, Nothing}
end

```

which gives me an error: `ERROR: LoadError: syntax: invalid variable expression in "where" around`. Is it possible to have a nested parametric type?

The reason I’m doing this is because I want to let the type `Data` to be flexible/extendable and eventually I want to replace it with `AbstractData{N,T}` such that I can add more data members when I need. For example,

```julia
mutable struct Data2{N,T} <: AbstractData{N,T}
	pos::SVector{N,T}
	mass::T
	charge::T
end

```

and I want `Node` to be aware of what kind of AbstractData it carries.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 26, 2021, 11:34am UTC](https://discourse.julialang.org/t/nested-parametric-type/58009/2 "2021-03-26T11:34:35Z")

</div>

```julia
mutable struct Node{N, T, D<:Data{N,T}}
    center::SVector{N,T}
    p::Union{D, Nothing}
    child::Union{Array{Node{N,T},1}, Nothing}
end

```

might be what you want.

---

<div class="post-metadata">

**Author:** ![huchiayu0517](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/huchiayu0517/32/8202_2.png) [@huchiayu0517](https://discourse.julialang.org/u/huchiayu0517)\
**Post date:** [March 26, 2021, 11:47am UTC](https://discourse.julialang.org/t/nested-parametric-type/58009/3 "2021-03-26T11:47:28Z")

</div>

Yes, It works! Awesome!!!
