If I define a struct in Julia, is it possible to declare the type of one of its fields to be of the same type as the struct itself? For example, I want to define a struct NodeStruct with two fields, data and next where data is some standard type (e.g. AbstractFloat) and next is NodeStruct type or nothing. Consider this example code which gives an error LoadError: UndefVarError: NodeStruct not defined.
import Base.@kwdef
@kwdef mutable struct NodeStruct{A<:AbstractFloat, B<:Union{NodeStruct, Nothing}}
data ::A
next ::B
end
Is it possible to do this somehow? I would like to be able to do this parametrically as the performance tips suggest this and computation time is very important to me. I could not find any information in the documentation on types or constructors that resolves this issue.