F# comparing discriminated unions' by case identifier
问题 Is there a way to compare discriminated unions by their case-identifiers in F#? type MyUnion = | MyString of string | MyInt of int let x = MyString("hello") let y = MyString("bye") let z = MyInt(25) let compareCases a b = // compareCases x y = true // compareCases x z = false // compareCases y z = false How do I implement compareCases function in a generic way? I.e. something like the following, but more generic (reflection is ok): let compareCases a b = match a with | MyString(_) -> match b