>>> import GHC.Internal.Data.IORef >>> r <- newIORef 0 >>> readIORef r 0 >>> writeIORef r 1 >>> readIORef r 1 >>> atomicWriteIORef r 2 >>> readIORef r 2 >>> modifyIORef' r (+ 1) >>> readIORef r 3 >>> atomicModifyIORef' r (\a -> (a + 1, ())) >>> readIORef r 4See also STRef and MVar.
>>> ref <- newIORef 42 >>> atomicModifyIORef ref (\a -> (a, a + 3)) 45 >>> readIORef ref 42
>>> ref <- newIORef 42 >>> atomicModifyIORef' ref (\a -> (a, a + 3)) 45 >>> readIORef ref 42
>>> ref <- newIORef 42 >>> atomicModifyIORef'_ ref (`div` 2) >>> readIORef ref 21
>>> ref <- newIORef 42 >>> atomicModifyIORef_ ref (`div` 2) >>> readIORef ref 21
>>> ref <- newIORef 42 >>> atomicWriteIORef ref 45 >>> readIORef ref 45
>>> ref <- newIORef 42 >>> modifyIORef ref (\a -> a + 6) >>> readIORef ref 48
>>> ref <- newIORef 42 >>> modifyIORef' ref (\a -> a + 3) >>> readIORef ref 45
>>> ref <- newIORef False >>> :t ref ref :: IORef Bool
>>> ref <- newIORef 42 >>> readIORef ref 42
>>> ref <- newIORef 42 >>> writeIORef ref 43 >>> readIORef ref 43