Haskell Language Parallelism The Eval Monad


Parallelism in Haskell can be expressed using the Eval Monad from Control.Parallel.Strategies, using the rpar and rseq functions (among others).

f1 :: [Int]
f1 = [1..100000000]

f2 :: [Int]
f2 = [1..200000000]

main = runEval $ do
  a <- rpar (f1) -- this'll take a while...
  b <- rpar (f2) -- this'll take a while and then some...
  return (a,b)

Running main above will execute and "return" immediately, while the two values, a and b are computed in the background through rpar.

Note: ensure you compile with -threaded for parallel execution to occur.