# Mutually recursive type

**URL:** <https://discourse.julialang.org/t/mutually-recursive-type/25536>\
**Category:** General Usage\
**Created:** [June 21, 2019, 6:55pm UTC](https://discourse.julialang.org/t/mutually-recursive-type/25536 "2019-06-21T18:55:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)\
**Post date:** [June 21, 2019, 7:13pm UTC](https://discourse.julialang.org/t/mutually-recursive-type/25536/2 "2019-06-21T19:13:57Z")

</div>

Hi Freddy and welcome!

fyi, [dependent type](https://en.wikipedia.org/wiki/Dependent_type) means something else. What you’re trying are usually called _mutually recursive types_.

an internal constructor is the normal method.

```julia
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.

---

_[View the full topic](https://discourse.julialang.org/t/mutually-recursive-type/25536)._
