在尝试了解有关计算表达式如何工作的更多信息时,我正在尝试编写一个构建器,该构建器在评估语句then块后跳过表达式的其余部分if,因此工作流本身将评估为true. false如果没有任何if语句评估为,则工作流应返回true。
例如:
let mutable x = 0
let result =
earlyExit {
if false then x <- 99
if true then x <- 33
if true then x <- 11
}
在这里,result应该是true,而且x应该是33。
我得到的最接近的是:
type EarlyExitBuilder () =
member this.Combine (a, b) = a || b ()
member this.Delay fn = fn
member this.Run fn = fn ()
member this.Zero () = false
...这导致工作流评估为false和。x11
使用我的示例中的语法是否可行?