# Recurrent struct hierarchy

**URL:** <https://discourse.julialang.org/t/recurrent-struct-hierarchy/86094>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 21, 2022, 4:27pm UTC](https://discourse.julialang.org/t/recurrent-struct-hierarchy/86094 "2022-08-21T16:27:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfinke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfinke/32/38995_2.png) [@tfinke](https://discourse.julialang.org/u/tfinke)\
**Post date:** [August 21, 2022, 4:27pm UTC](https://discourse.julialang.org/t/recurrent-struct-hierarchy/86094/1 "2022-08-21T16:27:14Z")

</div>

Hi all,

I am trying to create a struct that contains a substruct at different levels. An instance `foo` of that struct should have the following layout:

```julia
foo.a
foo.b
foo.x.a
foo.x.b
foo.y.a
foo.y.b
foo.z

```

So `foo.x` and `foo.y` should contain components `a, b` of the same type as `foo` itself.  
My list `a, b` is of course remarkably longer and I would avoid code doubling.

Thanks for any advice

Torsten

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 22, 2022, 11:04am UTC](https://discourse.julialang.org/t/recurrent-struct-hierarchy/86094/2 "2022-08-22T11:04:13Z")

</div>

See [Mixers.jl](https://github.com/rafaqz/Mixers.jl) and [CompositeStructs.jl](https://github.com/marius311/CompositeStructs.jl).

```julia
julia> using CompositeStructs

julia> struct Struct_abc
         a::Vector{Int}
         b::String
         c::Dict{Char, Float64}
       end

julia> @composite struct FooStruct2
         Struct_abc...
         x::Struct_abc
         y::Struct_abc
         z::Int
       end

julia> x = Struct_abc([2, 3], "b", Dict('x'=>1));

julia> y = Struct_abc([5, 7], "B", Dict('y'=>1));

julia> foo = FooStruct2([1, 1, 1], "this is b", Dict('c'=>1.0), x, y, 42)
FooStruct2([1, 1, 1], "this is b", Dict('c' => 1.0), Struct_abc([2, 3], "b", Dict('x' => 1.0)), Struct_abc([5, 7], "B", Dict('y' => 1.0)), 42)
```

---

<div class="post-metadata">

**Author:** ![tfinke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfinke/32/38995_2.png) [@tfinke](https://discourse.julialang.org/u/tfinke)\
**Post date:** [August 22, 2022, 11:32am UTC](https://discourse.julialang.org/t/recurrent-struct-hierarchy/86094/3 "2022-08-22T11:32:54Z")

</div>

thanks! `CompositeStructs` is exactly, what I was looking for. Great!
