这是来自Expert 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)))))

关于f# - 这对计算工作流程是否正确?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6182055/

10-11 17:46