As pad has pointed out - you don't need to qualify a union case with its parent type - so you can write
let makeUnion switch =
match switch with
| true -> TypeOne (new TypeOne ())
| false -> TypeTwo (new TypeTwo ())
However you will always have to specify the TypeOne
. This is to avoid the ambiguity present if you have multiple cases which take the same arguments - like
type foo=
|Bar of int
|Baz of int
Then even knowing the return type, the compiler can't work out what to return. A more common example is actually with cases which take no arguments - say you decide to redifine true and false:
type bool = |True |False