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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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#_Computation Expression - Fatal编程技术网

F# 让我们一起来吧!在计算表达式中

F# 让我们一起来吧!在计算表达式中,f#,computation-expression,F#,Computation Expression,我目前正在制作神奇的fsharpforfunandprofit网站的计算表达式系列,我对计算系列的第4课“包装类型”有一个问题。我试着读得更深入一些,但有一个重要的概念我没有领会 实际上,我确实理解绑定的定义: member Bind : M<'T> * ('T -> M<'U>) -> M<'U> getCustomerId“Alice”将M这个给我: 将desugar命名为类似(将monad类型命名为justdb这正是Bind用于(展开)的内

我目前正在制作神奇的fsharpforfunandprofit网站的计算表达式系列,我对计算系列的第4课“包装类型”有一个问题。我试着读得更深入一些,但有一个重要的概念我没有领会

实际上,我确实理解绑定的定义:

member Bind : M<'T> * ('T -> M<'U>) -> M<'U>
getCustomerId“Alice”M这个给我:


将desugar命名为类似(将monad类型命名为just
db这正是
Bind
用于(展开)的内容):您可以将
let!custId=…
想象为just
Bind(getCustomerId“Alice”)(有趣的custId->…下一行)
所以每个
let!
都会让你获得另一个级别的
Bind
let!
本身就是要绑定的语法糖-你可以在这里面找到一些细节好的,明白了!太多了…想让我把它包装成一个答案吗?…有一刻我忘记了Bind方法Bind是什么(m,f)当匹配m时,它将f应用于a,从而展开值以备将来使用。非常感谢。
let product'' = 
    dbresult {
        let! custId = getCustomerId "Alice"
        let! orderId = getLastOrderForCustomer "" // error!
        let! productId = getLastProductForOrder orderId 
        printfn "Product is %s" productId
        return productId
        }
printfn "%A" product''
let product'' = 
    dbresult {
        let! custId = getCustomerId "Alice"
        let! orderId = getLastOrderForCustomer "" // error!
        let! productId = getLastProductForOrder orderId 
        printfn "Product is %s" productId
        return productId
        }
let product'' = 
   DB.Delay(fun () ->
       DB.Bind(getCustomerId "Alice",(fun custId ->
          DB.Bind(getLastOrderForCustomer "",(fun orderId ->
             DB.Bind(getLastProductForOrder orderId, (fun productId ->
                printfn "Product is %s" productId
                DB.Return productId)))))))