アクティブ パターンを使用して再帰降下パーサーを作成することで F# を学習しています。
すべてのルールまたは部分的なアクティブ パターンをさまざまな方法で組み合わせる必要があるため、アクティブ パターンをパラメーターとして渡す構文に本当に不満を感じています。
次の例は、私が抱えている問題を示しています。
// Combines two patterns by chaining them.
let (|Chain|_|) (|Pattern1|_|) (* Should I use pipes here? *) (|Pattern2|_|) data =
match data with
|Pattern1 result ->
match result with
|Pattern2 result2 -> Some result2
|_ -> None
|_ -> None
// Stupid test patterns
let (|IfBiggerThan10ThenDouble|_|) value = if value > 10 then Some (value*2) else None
let (|IfLessThan100ThenDouble|_ |) value = if value < 100 then Some (value*2) else None
match 20 with
// Do I need pipes here?
|Chain (IfBiggerThan10ThenDouble IfLessThan100ThenDouble) value -> printfn "%A" value // Should print 80
| _ -> printfn "Did not match"
私の主な混乱は、「|」についてのようです オペレーター。柄の種類の一部と思われることもあれば、名前の一部と思われることもあります。