1

我很难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)只是一些涉及xand的布尔表达式y

4

1 回答 1

0

找到了:

let condition p guard = ( fun () ->
    match p() with
    | Some x when guard x -> Some x
    | _ -> None )
于 2017-08-23T23:12:23.267 回答