Skip to content
Snippets Groups Projects
Commit 0fafbcb0 authored by sof's avatar sof
Browse files

[project @ 1999-09-20 10:22:40 by sof]

Added 'updateIORef :: IORef a -> (a->a) -> IO ()'
parent d82f4142
No related merge requests found
......@@ -22,6 +22,7 @@ module IOExts
, newIORef
, readIORef
, writeIORef
, updateIORef
, mkWeakIORef
......@@ -106,9 +107,9 @@ unsafePtrEq a b =
\end{code}
\begin{code}
newIORef :: a -> IO (IORef a)
readIORef :: IORef a -> IO a
writeIORef :: IORef a -> a -> IO ()
newIORef :: a -> IO (IORef a)
readIORef :: IORef a -> IO a
writeIORef :: IORef a -> a -> IO ()
#ifdef __HUGS__
type IORef a = STRef RealWorld a
......@@ -124,6 +125,13 @@ readIORef (IORef var) = stToIO (readVar var)
writeIORef (IORef var) v = stToIO (writeVar var v)
#endif
updateIORef :: IORef a -> (a -> a) -> IO ()
updateIORef ref f = do
x <- readIORef ref
let x' = f x
writeIORef ref x'
-- or should we return new value ? (or old?)
mkWeakIORef :: IORef a -> IO () -> IO (Weak (IORef a))
mkWeakIORef r@(IORef (MutableVar r#)) f = IO $ \s ->
case mkWeak# r# r f s of (# s1, w #) -> (# s1, Weak w #)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment