4

次の形式の判別共用体をアクティブなパターン マッチングで使用する方法はありますか? 例を見つけることができませんでした。

これは私がやろうとしていることです:

type c = a | b

type foo =
  | bar1
  | bar2 of c

//allowed
let (|MatchFoo1|_|) aString =
  match aString with
  | "abcd" -> Some bar1
  | _ -> None

//not allowed
let (|MatchFoo2|_|) aString =
  match aString with
  | "abcd" -> Some (bar2 of a)
  | _ -> None

「Some」を 2 番目の方法で使用できないのはなぜですか? 同じことを達成する別の方法はありますか?

4

1 に答える 1