Types of nested connections in F #

Is there a way to insert nested union types in F #? Something like that


type MainType =
    | A of
        | AA of int
        | AB of float
    | B of int   
+5
source share
2 answers

No, you have to separate the types (as in kvb post). I heard about plans to add polymorphic variance (as in ocaml) to F # , which will allow you to do something like this.

In ocaml,

type mainType =
    | A of [ `AA of int | `AB of float ]
    | B of int   
+2
source

No, I do not think so. It does not seem to be very beneficial for creating two separate types of union, such as:

type NestedType =
| AA of int
| AB of float

type MainType =
| A of NestedType
| B of int

let mainValue = A (AA 1)
+2
source

All Articles