Mutually recursive type

Hi Freddy and welcome!

fyi, dependent type means something else. What you’re trying are usually called mutually recursive types.

an internal constructor is the normal method.

julia> struct A{T}
           b::T
           A(x) = new{B}(x)
       end

julia> struct B
           a::Union{A,Nothing}
       end

julia> A(B(A(B(nothing))))
A{B}(B(A{B}(B(nothing))))

This is kind of a workaround until Julia gets forward declarations or becomes aware of mutually recursive types.

But it works. Let us know if you want further explanation of this idiom.

3 Likes