seq vs. pseq

Malcolm Wallace Malcolm.Wallace at
Fri Oct 27 11:27:48 EDT 2006

Simon Marlow <simonmarhaskell at> wrote:

> The difference is subtle.  The semantics of seq and pseq are
> identical; however,  GHC can see that seq is strict in both its
> arguments and hence could choose to  evaluate them in either order,
> whereas pseq is only strict in its first argument  as far as the
> strictness analyser is concerned.  The point is that pseq is  useful
> for controlling evaluation order, which is what you want for adding 
> parallelism to a program.  seq, on the other hand, is not useful for
> controlling  evaluation order.

This is a rather weird thing, and I would consider it a bug in the
Haskell Report, rather than a bug in ghc.  (It bites hard when you are
trying to implement something like HPC.)

The very name 'seq' surely suggests that you are controlling the
evaluation order.  "Please evaluate this thing on the left first".  But
that is _not_ what the Haskell Report says!  Ghc takes the Report
literally, and so the thing on the right is just as likely to be
evaluated before the thing on the left!

Surely the language designers did not intend this consequence.  For
Haskell-prime, can we fix this bug, and ensure that 'seq' really implies
ordering of evaluation?

[ If you just want strictness annotations, with the compiler free to
  reorder computations, I would say ($!) is a better bet, and could be
  redefined to use not the natural `seq`, but the strict-in-both-arguments
  variation. ]


More information about the Glasgow-haskell-users mailing list