I'm trying to create a simple example doing a parallel evaluations:
import Control.Parallel.Strategies
main = do
  runEval $ do
    a <- rpar (\x -> x + 5)
    b <- rseq (\x -> x + 15)
    return (a, b)
It says
Couldn't match expected type `IO t0'
                with actual type `(Integer -> Integer, Integer -> Integer)'
I know, it's not related to parallelism in Haskell, but nonetheless, how do I build such a simple example in Haskell?
The problem is with the way you are using the lambdas. The types of rpar and rseq is a -> Eval a but the lambdas you passed has obviously type Integer -> Integer because you didn't passed an argument to the lambdas. 
Something like this compiles (also note that you need to print the result):
main = do
    print $ runEval $ do
        a <- rpar $ (\x -> x + 5) 4
        b <- rseq $ (\x -> x + 15) 4
        return (a, b)
To learn more about parallel processing in Haskell. There is a great book called "Parallel and Concurrent Programming in Haskell" by Simon Marlow, the HTML version is available for free here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With