RE: atomicModifyIORef

"Simon Marlow" <[email protected]> Mon, 28 Jun 2004 11:16:49 +0100
Newsgroups gmane.comp.lang.haskell.ffi
Message-ID <3429668D0E777A499EE74A7952C382D1020F29A2@EUR-MSG-01.europe.corp.microsoft.com>
On 25 June 2004 15:09, Daan Leijen wrote:

> Ok, I never thought of that. However, isn't it the case
> that I normally just want to get the old value back?
> In that case, the current interface is not so friendly.
> 
> Is anyone using this function to get something else than the
> old/new value *and* where the computation is expensive?
> 
> If not, maybe we should (also) provide a nicer interface?

I've no objection to providing simpler versions of the more general
interface - in fact I believe we discussed this when atomicModifyIORef
was introduced.  How about:

 atomicModifyIORef_ :: IORef a -> (a -> a) -> IO a
 atomicModifyIORef_ r f = atomicModifyIORef r (\a -> (f a, a))

If this turned out to be a common case that needs to be fast, then we
can implement it using a primitive in GHC.

Cheers,
	Simon