I’m working on a tree code where I have defined the following types:
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
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,
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.