有关F#功能的建议

时间:2013-11-23 13:46:51

标签: f# parallel-processing functional-programming task-parallel-library

我目前正在学习F#并需要一些关于此功能的建议......我正在测试Parallel.Invoke。最后一行是抛出一个意外的标识符错误。非常感谢。

let pmap_tpl_parin f (xs:Array<_>) =
let new_xs = Array.zeroCreate xs.Length
let j = xs.Length - 1
for k in 0..4 do
    Parallel.Invoke (new Action(fun () -> (  for i in  j do   (fun i -> new_xs.[i] <- f (xs.[i]) ))) 
new_xs

1 个答案:

答案 0 :(得分:3)

您在倒数第二行错过了结束)。看起来你想要:

let pmap_tpl_parin f (xs: _ array) =
    let new_xs = Array.zeroCreate xs.Length
    let j = xs.Length - 1
    for k in 0..4 do
        Parallel.Invoke (new System.Action(fun () -> (for i in j do (fun i -> new_xs.[i] <- f (xs.[i]) ))))
    new_xs