[英]F# not able to solve function in async
I'm really F# noob and I tried to code very simple program which iterate list in parallel. 我真的是F#新手,我尝试编写一个非常简单的程序来并行访问列表。 Here is simplified code 这是简化的代码
let test = ["xx"; "yy"; "zz"]
let urls =
["http://google.com";"http://google.com"]
let p l = async {
let t = test
for k in t do
printf "%s" k
}
let find =
urls
|> List.map p
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
[<EntryPoint>]
let main argv =
find
printfn "%A" argv
0 // return an integer exit code
Unfortunately this program never finish. 不幸的是,该程序从未完成。 It can't solve this line: 它无法解决这一行:
let t = test
It never get over that line. 它永远不会超越那条线。 But if I change find and main function in this way: 但是,如果我以这种方式更改find和main函数:
let find =
urls
|> List.map p
|> Async.Parallel
[<EntryPoint>]
let main argv =
find
|> Async.RunSynchronously
|> ignore
printfn "%A" argv
0 // return an integer exit code
Everything works fine as expected. 一切正常。 Can somebody explain me the difference please? 有人可以解释一下我的区别吗?
Also if I do not call test function but rather code list into "p" function 另外,如果我不调用测试函数,而是将代码列表转换为“ p”函数
let t = ["xx"; "yy"; "zz"]
It works fine in first version. 它在第一个版本中工作正常。
So the problem is that find
is not a function, but a value. 因此,问题在于find
不是函数,而是值。 As a result find
actually runs before main
(in the first example). 结果, find
实际上在main
之前运行(在第一个示例中)。
Changing the definition to let find()
seems to work fine for me. 更改定义以let find()
对我来说似乎很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.