<div style="min-height:22px;margin-bottom:8px;">+1, BTW. let's call it atomicSwapIORef to keep sync with MVar/TVar's counterpart.</div><div style="min-height:22px;margin-bottom:8px;"><br></div><span class="mail-footer" aria-hidden="true">·¢×ÔÎÒµÄiPhone</span><div id="original-content"><br><br><div><div style="font-size:70%;padding:2px 0;">------------------ Original ------------------</div><div style="font-size:70%;background:#f0f0f0;color:#212121;padding:8px;border-radius:4px"><div><b>From:</b> David Feuer <david.feuer@gmail.com></div><div><b>Date:</b> Sat,Jun 23,2018 4:15 PM</div><div><b>To:</b> Haskell Libraries <libraries@haskell.org></div><div><b>Subject:</b> Re: Proposal: Add an atomic IORef replacement operation</div></div></div><br><div dir="auto">Currently, atomicWriteIORef is implemented using atomicModifyIORef. This is not ideal: the latter allocates memory while the former shouldn't need to. In the process of writing alternative implementations, I realized that we can efficiently support an atomic operation that replaces the value in an IORef, returning the previous value. I propose that we add, to Data.IORef, a function to do so:<div dir="auto"><br></div><div dir="auto">atomicReplaceIORef :: IORef a -> a -> IO a</div></div>
</div>