I found some sample code, and changed it a little
counter = unsafePerform $ newIORef 0
newNode _ = unsafePerformIO $
do
i <- readIORef counter
writeIORef counter (i+1)
return i
Which returns 1 then 2 then 3 then 3 etc each time it's run.
But when I change it to
newNode = unsafePerformIO $
do
i <- readIORef counter
writeIORef counter (i+1)
return i
then I get 0 every time I run it.
Why is this happening, and what can I do to fix it?