Angelica
Angelica

Reputation: 11

What am I doing wrong in this F# code?

let parallelTest n = Color(Color.DeepPink, Triangles(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.

Upvotes: 1

Views: 228

Answers (3)

Brian
Brian

Reputation: 118865

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.

Upvotes: 4

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99720

Compose your function with ignore to make it return unit:

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

Upvotes: 5

Dario
Dario

Reputation: 49208

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?

Upvotes: 0

Related Questions