Reputation: 20004
Is there any way to crate nested union types in F#? Something like this
type MainType =
| A of
| AA of int
| AB of float
| B of int
Upvotes: 6
Views: 962
Reputation: 47934
No, you'll have to separate the types(as in kvb's post). I have heard of plans to add polymorphic variance (as in ocaml) to F#, which would allow you to do something similar.
In ocaml,
type mainType =
| A of [ `AA of int | `AB of float ]
| B of int
Upvotes: 2
Reputation: 55184
No, I don't think so. The doesn't seem to be much advantage over creating two separate union types like:
type NestedType =
| AA of int
| AB of float
type MainType =
| A of NestedType
| B of int
let mainValue = A (AA 1)
Upvotes: 4