[Haskell-cafe] Go parallel
bulat.ziganshin at gmail.com
Mon Nov 5 19:43:30 EST 2007
Tuesday, November 6, 2007, 3:13:05 AM, you wrote:
> Is it possible to use the forkIO primitive to cause pure computations
> to be evaluated in parallel threads?
> It seems to me that laziness would always prevent any evaluation until
> the result was used in a consuming thread (and hence would occur
> serially, in that thread).
yes, that's true. but we can force evaluation of array elements:
task (i,j) = do putArray arr (i,j) (i*j)
return $! getArray arr (i,j)
in the Andrew's case, array in unboxed, so putArray will evaluate its
argument without additional return$!
on the other side, he can use boxed immutable array and use tasks
exactly to enforce evaluation of lazy boxes:
let arr = array (0,0) (10,10) [i*j | i<-0..10, j<-0..10]
let task (i,j) = return $! elemArray arr (i,j)
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe