Either I’ve found a compiler bug or I’m trying to do something so stupid the compiler won’t let me.
Directly from the docs I can coerce a polymorphic variant to a string:
type company = [#Apple | #Facebook]
let theCompany: company = #Apple
let message = "Hello " ++ (theCompany :> string)
I can turn this into a lower bounded variant as follows, if I specify the type of the specific instance of the lower bounded variable:
type company<'a> = [> #Apple | #Facebook] as 'a
let theCompany: company<[#Apple | #Facebook | #Google]> = #Apple
let message = "Hello " ++ (theCompany :> string)
However, if I leave the generic as a lower bounded variant, it fails to compile:
type company<'a> = [> #Apple | #Facebook] as 'a
let theCompany: company<'a> = #Apple
let message = "Hello " ++ (theCompany :> string)
I don’t really have any context to provide because I’m just playing around to see how far I can push the language. I have it in mind I can use some of this for some generic database bindings, but I’m not actively trying to do anything with it right now.