Created
December 8, 2011 16:37
-
-
Save acfoltzer/1447533 to your computer and use it in GitHub Desktop.
Pointer equality woes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.CAS | |
import Data.IORef | |
test1 = do ref <- newIORef 0 | |
let old = 0 | |
new = (old+1) | |
casIORef ref old new | |
test2 = do let old = 0 | |
ref <- newIORef old | |
let new = (old+1) | |
casIORef ref old new | |
main = (print =<< test1) >> (print =<< test2) | |
{- Unboxing from optimizations affects the semantics: | |
afoltzer@mbp scratch$ ghc -fforce-recomp --make -O0 cas.hs && ./cas | |
[1 of 1] Compiling Main ( cas.hs, cas.o ) | |
Linking cas ... | |
(False,0) | |
(True,0) | |
afoltzer@mbp scratch$ ghc -fforce-recomp --make -O1 cas.hs && ./cas | |
[1 of 1] Compiling Main ( cas.hs, cas.o ) | |
Linking cas ... | |
(True,0) | |
(True,0) | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment