[Haskell] ANNOUNCING: The Haskell Bookstore

Daan Leijen daanleijen at xs4all.nl
Fri Jun 25 06:30:14 EDT 2004


Is there anyone who knows why "atomicModifyIORef" has type:

  IORef a -> (a -> (a, b)) -> IO b		(1)

Instead of:

  IORef a -> (a -> a) -> IO a			(2)


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 makes much more sense to me to have type (2), the scope
for errors and code duplication is much lower in my opinion.

All the best,
  Daan.




More information about the FFI mailing list