Effects of Monads in Parallelisation

Dear List, I am currently trying to understand the effects of monads in the sense of parallelisation in Haskell. Could somebody please explain the difference between 'rpar' and 'par'? I mean, what has been changed after the encapsulation of 'par' function by Eval monad? If you asked to compare the parallelisation via monads with non-monadic manner of it, what could you say? Many thanks in advance. All the best, Burak.

2011/7/26 Burak Ekici
what has been changed after the encapsulation of 'par' function by Eval monad?
If you asked to compare the parallelisation via monads with non-monadic manner of it, what could you say?
'Eval' provides some useful discipline and structure. It allows you to more clearly start sparks or sequence certain evaluations before you progress past the 'using' or 'withStrategy' directive, even if you don't need the output right away. rpar x = x `par` return x rseq x = x `pseq` return x data Eval a = Done a runEval :: Eval a -> a runEval (Done x) = x instance Monad Eval where return x = Done x Done x >>= k = k x You will eventually 'runEval' to extract the evaluated result. This is strict on the monad itself - i.e. you pattern-match against 'Done' in both 'runEval' and in the binding operator (>>=). Therefore, you know that ALL your 'rseq' and 'rpar' statements have finished executing before you get past 'runEval'. Without use of a monad, this is a bit more difficult - i.e. a use of 'par' might be buried deep in some lazy evaluation, unless you're very careful.
participants (2)
-
Burak Ekici
-
David Barbour