F# Circular Type Definition Loop

568 views Asked by At

I want to have a type A which has a property which is an instance of type B. And type B has a property of an instance of type A. The problem is, F# reads the source files in order. So if I define type A first, then it won't recognize type B. And if I define type B first, I can't make it have an instance of A. Is there a way around this, or is this just bad design on my part?

1

There are 1 answers

0
Daniel Slater On BEST ANSWER

You can a define mutually recursive type if they are in the same file like this

type Chicken =
   | Eggs of Egg list
and Egg =
   | Chickens of Chicken list