Skip to content

Instantly share code, notes, and snippets.

@acfoltzer
Created December 8, 2011 16:37
Show Gist options
  • Save acfoltzer/1447533 to your computer and use it in GitHub Desktop.
Save acfoltzer/1447533 to your computer and use it in GitHub Desktop.
Pointer equality woes
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