Attempting to do some asynchronous programming via threads. To start with, I am trying a simple case: mapping a list in parallel. The code so far looks like:
let doWork (x:('a -> string)) (y:'a) (z:string ref) (finished:bool ref) =
ThreadPool.QueueUserWorkItem( fun _ -> z:= x y
finished:= true)
let dualmap (x:'a list) (y:'a -> string) (z:string -> 'b) =
let acc = []
let rec dual (x:'a list) (y:'a -> 'b) (acc:'b list) =
match x with
| [] -> acc
| [i] -> (y i)::acc
| i::j::tl -> let un = ref ""
let deux = ref ""
let unfin = ref false
let deuxfin = ref false
doWork y i un unfin |> ignore //case i
doWork y j deux deuxfin |> ignore //case j
while not(unfin)||not(deuxfin) do Thread.Sleep(0)
let uno = z !un
let dos = z !deux
dual tl y (dos::(uno::acc))
dual x y acc
However, I am not sure how to get the threads to do work, since they seem to be obj -> unit rather than 'a -> 'b or 'a -> 'b -> 'c, which is what I would need.
Instead, I have to make sure I know how to convert every object I hve into a string, and then convert it back. It seems like there must be an easier way to do this?
Are you wanting to do something like this?