pseq strictness properties

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Fri Nov 21 06:37:48 EST 2008


Duncan Coutts <duncan.coutts at worc.ox.ac.uk> wrote:

> I guess we can try to simplify it to something like "evaluation
> happens here" (pseq) vs "evaluation happens here or before" (seq).

No, that is not correct, or at least it is highly misleading.  The key
difference between them is that:

  (x `pseq` y) = if y is not yet in WHNF, the compiler guarantees that
                 x will be evaluated to WHNF before y.
  (x `seq` y)  = if y is not yet in WHNF, the compiler can choose
                 whether to evaluate y to WHNF before x, or x before y.

In other words, pseq guarantees sequencing (given a side condition),
whilst seq does not guarantee sequencing.

Regards,
    Malcolm


More information about the Glasgow-haskell-users mailing list