这是来自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)))))
答案 0 :(得分:2)
是的,这本书中的错误,应该如下所示:
attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 -> let sum = n1 + n2 in
attempt.Return sum)))))