在F#中,案例标识符的'是X'运算符?

Gre*_*Ros 1 .net f# functional-programming

假设我有以下有区别的联合和价值:

type DisUnion = 
    | One of string
    | Two of string
    | Three of string * string

let myVal = One("One")
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用模式匹配来确定myVal属于哪种情况,如下所示:

let whatever (x : DisUnion) = match x with
    | One(str) -> "It was One"
    | Two(str) - > "It was two"
    | Three(str, str) -> "It was three"
Run Code Online (Sandbox Code Playgroud)

但我似乎找不到允许我在没有模式匹配的情况下确定案例标识符的运算符或方法,例如:

let isOne (x : DisUnion) = x :? One //I thought this would work, but it doesn't.
Run Code Online (Sandbox Code Playgroud)

我该怎么做?任何帮助表示赞赏.

Lee*_*Lee 6

let isOne = function One(_) -> true | _ -> false
Run Code Online (Sandbox Code Playgroud)

请注意,这相当于:

let isOne x = match x with One(_) -> true | _ -> false
Run Code Online (Sandbox Code Playgroud)