Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 这是计算工作流程的正确设计吗?_F#_Workflow_Bind - Fatal编程技术网

F# 这是计算工作流程的正确设计吗?

F# 这是计算工作流程的正确设计吗?,f#,workflow,bind,F#,Workflow,Bind,这来自专家F#2.0第231页。显然,下面的代码块 attempt { let! n1 = failIfBig inp1 let! n2 = failIfBig inp2 let sum = n1 + n2 return sum };; 除糖: attempt.Bind( failIfBig inp1,(fun n1 -> attempt.Bind(failIfBig inp2,(fun n2 -> attempt.Return sum))))) 但是在脱糖变量中,sum在哪里计

这来自专家F#2.0第231页。显然,下面的代码块

attempt { let! n1 = failIfBig inp1
let! n2 = failIfBig inp2
let sum = n1 + n2
return sum };;
除糖:

attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 ->
attempt.Return sum)))))
但是在脱糖变量中,
sum
在哪里计算?我还以为会是这样:

attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 -> let sum = n1 +  n2 in
attempt.Return sum)))))

是的,这是本书中的一个错误,应按如下方式进行脱糖:

attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 -> let sum = n1 +  n2 in
attempt.Return sum)))))

是的,翻译完全如您在第二个代码片段中所示。(如果计算budilder定义了
延迟
运行
,则会更复杂,但我认为这里不是这样)在我的书的免费提供的第12章中也有一些翻译示例:将计算表达式包装在引号中也将帮助您了解它们是如何被删除的。Unquote()可以使这一点更加清楚,因为至少在1.3.0版本中,它不会“重新添加”它们。