
15 Jan
2021
15 Jan
'21
8:05 p.m.
GHC.IORef currently exports atomicModifyIORef2 :: IORef a -> (a -> (a,b)) -> IO (a, (a, b)) atomicSwapIORef :: IORef a -> a -> IO a atomicModifyIORef2 is a lot like atomicModifyIORef, but it returns both the old value in the IORef and the full result of applying the user-supplied function to that. This is a pretty thin wrapper around the newish atomicModifyMutVar2# primop, which has replaced the less powerful atomicModifyMutVar#. atomicSwapIORef atomically installs a user-supplied value in an IORef and returns the old value. It is currently implemented using atomicModifyIORef2, but it can and should be reimplemented using its own, more efficient primop. I propose to add both of these functions to Data.IORef. David