You could try with meta programming
abstract type AbstractCompound{N} end
for N = 1:4
name = Symbol("Compound$N")
@eval begin
struct $name <: AbstractCompound{$(N)} # N is the number of spatial dimensions of the field
scalar_field :: Array{Float64,$(N)}
vector_field :: Array{Float64,$(N+1)}
tensor_field :: Array{Float64,$(N+2)}
end
end
end
julia> c = Compound1(zeros(1),zeros(1,1),zeros(1,1,1))
Compound1([0.0], [0.0], [0.0])
julia> c.tensor_field
1×1×1 Array{Float64, 3}:
[:, :, 1] =
0.0