Consider the following two statements:
(a `par` b) `pseq` (a + b)
and
a `par` (b `pseq` (a + b))
Can someone explain how their behavior differ from each other?
For the first one, if the main thread has done with computing b but the spark computing a hasn’t finished, will the main thread proceed to compute a + b?
par a bis semantically equivalent tob, but it gives the hint that it might be useful to start evaluatingaearly. On the otherhandpseqforces the evaluation of its first argument, but is simply the (lazy) identity function in its second argument.So,
is semantically equivalent to
which is equivalent to
in that the both say “evaluate
bthen become the thunka + b“. Given the non precision in the consequences ofparno other difference can be gleamed from the language definition. Rather, on your particular compiler/runtime they might do slightly different things.