Jan-Willem Maessen wrote:
On Dec 5, 2007, at 3:58 AM, Simon Marlow wrote:
Ah, so I was thinking of the following readIVar:
readIVar = unsafePerformIO . readIVarIO
But clearly there's a better one. Fair enough.
Hmm, so unsafePerformIO doesn't deal with any operation that blocks?
Well,
On Dec 5, 2007, at 3:58 AM, Simon Marlow wrote:
Jan-Willem Maessen wrote:
Consider this:
do
x - newIVar
let y = readIVar x
writeIVar x 3
print y
(I wrote the let to better illustrate the problem, of course you
can inline y if you want). Now suppose the compiler decided to
Jan-Willem Maessen wrote:
Consider this:
do
x - newIVar
let y = readIVar x
writeIVar x 3
print y
(I wrote the let to better illustrate the problem, of course you can
inline y if you want). Now suppose the compiler decided to evaluate y
before the writeIVar. What's to prevent
A pure readIVar would be just like lazy I/O, with similar drawbacks.
With readIVar, the effect that lets you observe the evaluation order
is writeIVar; with hGetContents it is hClose. Conclusion: it's
probably no worse than lazy I/O.
Actually, it's considerably better.
+: implementation
main = do
--irrelevant x - newIVar
let y = last [1..]
print test --was irrelevant writeIVar x 3
print y
Exactly. The termination concern doesn't seem to have to do with readIVar.
On Dec 4, 2007 11:56 AM, Isaac Dupree [EMAIL PROTECTED] wrote:
A pure readIVar would be