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?
Asked
Active
Viewed 532 times
0
-
1`type a() ... and b() ` - almost certainly a duplicate of something – John Palmer Jun 19 '15 at 13:05
-
Not exactly an answer to your question but this article gives a nice overview of the issue: http://fsharpforfunandprofit.com/posts/cyclic-dependencies/ – PiotrWolkowski Jun 19 '15 at 13:13
1 Answers
8
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

Daniel Slater
- 4,123
- 4
- 28
- 39