这是计算工作流程的正确脱糖吗?
这是来自 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)))))
This is from Expert F# 2.0 page 231. Apparently the following block of code
attempt { let! n1 = failIfBig inp1
let! n2 = failIfBig inp2
let sum = n1 + n2
return sum };;
de-sugars to this:
attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 ->
attempt.Return sum)))))
but where is sum
computed in the de-sugared variant? I expected something more like this:
attempt.Bind( failIfBig inp1,(fun n1 ->
attempt.Bind(failIfBig inp2,(fun n2 -> let sum = n1 + n2 in
attempt.Return sum)))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是书中的一个错误,应该按如下方式脱糖:
Yes it's an error in the book and it should be de-sugared as below: