
[redirecting to haskell-cafe] Simon Peyton-Jones wrote:
But since the read may block, it matters *when* you perform it. For example if you print "Hello" and then read the IVar, you'll block after printing; but if you read the IVar and then print, the print won't come out. If the operation was pure (no IO) then you'd have a lot less control over when it happened.
Well, the same can happen with any pure computation that does not terminate. It's the compiler's job to avoid that, and as far as I know ghc is pretty careful not to reorder pure computations and IO operations too much. I'd argue for adding both an IO and a pure version of readIVar to an IVar implementation. Both have their uses; the firts gives you a little extra control, while the second one can easily be evaluated on demand, at the risk of creating a mine field of potential deadlocks. Bertram