【发布时间】:2017-08-23 19:41:39
【问题描述】:
我很难在以下代码中为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 的布尔表达式。
【问题讨论】:
-
你想在这里实现什么?另请参阅how to create a Minimal, Complete, and Verifiable example。
-
这就是它...在 Expert F# 4.0 的第 475 页,您可以看到此示例,用于替换
if/then的自定义条件运算符。值condition没有具体定义。
标签: f# computation-expression custom-operator