I'm fairly new to F#, and I want to model things in the real world that have fairly complex "has-a" relationships. At the top of the hierarchy are four types, A - D, with these relationships:
A
|
+--A
|
+--B
| |
| +--B
| |
| +--D
| |
| +--D
|
+--C
| |
: +--D
| |
| +--D
:
So type B can have a "parent" of either A or B, and type D can have a parent of B, C or D.
I want to use discriminated unions to constrain the parent of each type, so they can't be assigned to invalid parents, e.g:
type B_Parent = A | B
type D_Parent = B | C | D
Then I want to use records to model each type, where one field is the parent, e.g:
type A = { parent:A_Parent; ... }
type B = { parent:B_Parent; ... }
type C = { parent:C_Parent; ... }
type D = { parent:D_Parent; ... }
C_Parent isn't a problem because its parent type A is declared beforehand. And I have used 'A option' for A_Parent. But I haven't been able to work out how to define B_Parent and D_Parent, because of their nested dependency on themselves, and on other types?