atomicModifyIORef

Daan Leijen daanleijen at xs4all.nl
Fri Jun 25 10:08:52 EDT 2004


Thanks Martin and Simon for your prompt feedback.
(and apologies for the wrong subject header)

On Fri, 25 Jun 2004 12:14:26 +0100, Simon Marlow <simonmar at microsoft.com> wrote:
>> It seems to me that returning the old value is always good
>> enough right?  Here is an implementation of "atomicModifyIORef"
>> with the current type in terms of a function "proposedModifyIORef"
>> with type (2).
>>
>> atomicModifyIORef :: IORef a -> (a -> (a,b)) -> IO b
>> atomicModifyIORef ref f
>>    = do old <- proposedModifyIORef ref (fst . f)
>>         return (snd (f old))
>
> Yes, but in your version you apply f to the old value twice, potentially
> duplicating an expensive computation.

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?


> atomicModifyIORef isn't part of the FFI spec, BTW.

Well, I asked about this as I was confused by the
type of this function: at first I thought that I was missing
some essential functionality :-)

-- Daan.


>
> Cheers,
> 	Simon
> _______________________________________________
> FFI mailing list
> FFI at haskell.org
> http://www.haskell.org/mailman/listinfo/ffi
>
>






More information about the FFI mailing list