<div dir="ltr"><div><div><div><div><div><div><div>I'm trying to understand why some code isn't behaving as I'd expect, and to determine whether it's a bug or not (and where that bug might be). Here's the simplest version of the code:<br>
<br> import Data.ByteString.Internal (inlinePerformIO)<br> import qualified Data.Vector as V<br> import qualified Data.Vector.Mutable as VM<br><br> main :: IO ()<br> main = do<br> vm <- VM.new 1<br>
VM.write vm 0 'A'<br> let x = inlinePerformIO $ VM.write vm 0 'B'<br> x `seq` (V.freeze vm >>= print)<br><br></div>A more complete example is available on lpaste[1].<br><br></div>
The problem is that I would expect the output to be "B", but in fact "A" is still printed. From the longer paste that I linked to, you can see that:<br><br></div>* When using unsafePerformIO and unsafeDupablePerformIO, the semantics work as I would have expected: "B" is printed after forcing evaluation of the result.<br>
</div>* If I add a `VM.read vm 0` call after the write, it also works.<br></div>* Using IORef, the behavior is also as I would have expected: as soon as the result is evaluated, the reference is updated.<br><br></div>I'm testing on GHC 7.8.3, Ubuntu 64-bit, and compiling with -O2. I'm curious if anyone has an idea as to why there is this difference in behavior.<br>
<br></div>Michael<br><div><div><div><div><div><div><div><br>[1] <a href="http://lpaste.net/108483">http://lpaste.net/108483</a><br></div></div></div></div></div></div></div></div>