我在以下代码中提出condition
的定义时遇到了严重困难。希望有一个例子和见解:
// a computation expression builder class
type Builder() =
.
.
.
[<CustomOperation( "condition",
MaintainsVariableSpaceUsingBind = true )>]
member this.Condition(p, [<ProjectionParameter>] b) =
condition p b
let attemp = AttemptBuilder()
let test =
attempt { let x, y = exp1, exp2
condition booleanExpr(x, y)
return (x, y) }
我认为b
隐含( fun x, y -> booleanExpr(x, y) )
。术语booleanExpr(x, y)
只是一些涉及x
和y
的布尔表达式。
答案 0 :(得分:0)
找到它:
let condition p guard = ( fun () ->
match p() with
| Some x when guard x -> Some x
| _ -> None )