The general approach that I would use here would be to match the join values ββin the tags identifying the cases, and then check if the resulting tag set has at most one element.
let allTheSameCase (tagger: 'a -> int) (coll: #seq<'a>) = let cases = coll |> Seq.map tagger |> Set.ofSeq Set.count cases <= 1
For the tagger function, you can assign tags manually:
allTheSameCase (function Number _ -> 0 | Word _ -> 1) lst
or use reflection (note that you may need to set the anchor flags as needed):
open Microsoft.FSharp.Reflection let reflectionTagger (case: obj) = let typ = case.GetType() if FSharpType.IsUnion(typ) then let info, _ = FSharpValue.GetUnionFields(case, typ) info.Tag else -1
source share