異なるタイプの配列の識別結合がある場合、それらを「実際の」タイプに変換するにはどうすればよいですか?
type ItemStuff =
| Colors of string[]
| Sizes of int[]
let foo = Sizes [|1;2;3|]
foo の値を取得したときに上記を実行すると、次のように表示されます。
val foo : ItemStuff = Sizes [|1;2;3|]
foo から int の実際の配列を取得するにはどうすればよいですか? のようなものにアクセスできる構文が欠けているだけ
foo.[2]
ですか? foo で列挙できないため、マップを使用できませんでした。返される配列の異なる型ごとに適切に型指定された配列を返す ItemStuff のメンバーを作成できますが、それは正しくないように思えましたか?
ここで私の最善のアプローチは何ですか?
これが私がやったことです。それを行うためのより良い方法についてのアイデアはありますか?
type ItemProp =
| Colors of string[]
| Sizes of int[]
| Quants of int[]
member this.GetColors() =
match this with
| Colors (stringArray) ->
stringArray
| _ -> null
member this.GetIntArr() =
match this with
| Sizes (intArray) | Quants (intArray) ->
intArray
|_ -> null
foo.GetIntArr()