I'm trying to understand why we need all parts of the standard sample code:
a `par` b `pseq` a+b
Why won't the following be sufficient?
a `par` b `par` a+b
The above expression seems very descriptive: Try to evaluate both a
and b
in parallel, and return the result a+b
. Is the reason only that of efficiency: the second version would spark off twice instead of once?
How about the following, more succinct version?
a `par` a+b
Why would we need to make sure b
is evaluated before a+b
as in the original, standard code?
seq
is insufficient for this problem.seq
makes no guarantees about ordering of evaluation. Inseq b (a+b)
, the main thread may evaluatea
beforeb
so long asb
is in WHNF when(a+b)
is evaluated. – Sexed