Tutorial by Examples

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 <- rpa...
rpar :: Strategy a executes the given strategy (recall: type Strategy a = a -> Eval a) in parallel: import Control.Concurrent import Control.DeepSeq import Control.Parallel.Strategies import Data.List.Ordered main = loop where loop = do putStrLn "Enter a number" ...
We can use rseq :: Strategy a to force an argument to Weak Head Normal Form: 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... rseq a return ...

Page 1 of 1