Re: [Haskell] ANNOUNCING: The Haskell Bookstore
Marcin 'Qrczak' Kowalczyk <[email protected]> Fri, 25 Jun 2004 12:32:17 +0200
| Newsgroups | gmane.comp.lang.haskell.ffi |
|---|---|
| Message-ID | <1088159538.29200.89.camel@qrnik> |
W liście z pią, 25-06-2004, godz. 12:30 +0200, Daan Leijen napisał(a):
> 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))
It applies f twice, which may duplicate work.
--
__("< Marcin Kowalczyk
\__/ [email protected]
^^ http://qrnik.knm.org.pl/~qrczak/