strange MVar / UnsafePerformIO (and type checker...) behaviour
Compare the following two code snippets:
import Data.Word
import Control.Concurrent.MVar
import System.IO.Unsafe
a :: MVar Int
a = unsafePerformIO newEmptyMVar
b :: MVar Word8
b = unsafePerformIO newEmptyMVar
main1 = do
putMVar a (-5)
putMVar b (-127)
x <- readMVar a
y <- readMVar b
print (x,y)
and (I omitted the imports here for brevity):
gvar :: MVar a
gvar = unsafePerformIO newEmptyMVar
a :: MVar Int
a = gvar
b :: MVar Word8
b = gvar
main = do
putMVar a (-5)
x <- readMVar a
y <- readMVar b
print (x,y)
The first version works as intended (and prints (-5,129)
). However, what happens in the second version, that it compiles without any warnings, but a
and b
becomes the same thing (prints (-5,-5)
), even though I declared them to have different types! I'm not sure what would be the correct behaviour, but I reckon this is not the correct one.
The effect is the same on 6.6.1 and 6.7.20070830, and was tested on an x86 machine running Mac OS X.
Trac metadata
Trac field | Value |
---|---|
Version | 6.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |