Using DeepSeq for exception ordering

Simon Hengel sol at
Thu Nov 8 13:12:23 CET 2012

Hi Edward,
thanks a lot for your reply.

> rnf can be thought of a function which produces a thunk (for unit)
> which, when forced, fully evaluates the function.  With this in hand,
> it's pretty clear how to use evaluate to enforce ordering:
>     evaluate (rnf ('a': throw exceptionA))

So if I understand correctly, then if I have

  evaluate (x_1 `seq` x_2 `seq` x_3 `seq` ... `seq` x_n)
  throwIO exceptionB

it is guaranteed that exceptionB can only happens if none of the xs are

I was just going to say that I can give at least one counterexample
where this does not hold:

  evaluate (('a' : undefined) `deepseq` return () :: IO ())
  throwIO exceptionB

But then I realized that here exceptionA is optimized away altogether.
For me this smells like a bug.  Is this related to [1]?



More information about the Glasgow-haskell-users mailing list