开发者

What am I doing wrong in this F# code?

开发者 https://www.devze.com 2022-12-08 09:55 出处:网络
let parallelTest n = Color(Color.DeepPink, Triangl开发者_如何学Pythones(sphere n));; Parallel.For(0,10,newAction(parallelTest));;

let parallelTest n = Color(Color.DeepPink, Triangl开发者_如何学Pythones(sphere n));;

Parallel.For(0,10,new Action(parallelTest));;

Error message : error FS0001: Type mismatch. Expecting a int -> unit but given a int -> scene. The type 'unit' does not match the type 'scene'

I'll glad if some body help me.


Compose your function with ignore to make it return unit:

Parallel.For(0, 10, parallelTest >> ignore)


If you want 10 results, perhaps you want

[| for i in 0..9 do
       async { return parallelTest i } |]
|> Async.Parallel
|> Async.RunSynchronously

This will return an array of 10 scene results.


At which position does this error message occur? (I can't reproduce the error since I don't know the delcarations of some functions you use)

I guess the following: Parallel.For expects a int -> unit (Action<int> in standard .NET), but parallelTest has a different type (int -> scene) which is therefore incompatible.

And what are you trying to achieve with the whole code?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号