Anonymous record type inside discriminated union
You can define mutually dependent types using and
:
type Employee =
| Engineer of Person
| Manager of Manager // manager has list of reports
| Executive of Executive
and Manager = { Name: Person; Reports: Employee list }
and Executive = { Name: Person; Reports: Employee list; Assistant: Employee }
If you're using F# v3.1 you can use named union fields [MSDN] (and protect your delicate sensibilities):
type Employee =
| Engineer of Person
| Manager of Name: Person * Reports: Employee list
| Executive of Name: Person * Reports: Employee list * Assistant: Employee