module Data.IORef.Extra(
module Data.IORef,
writeIORef', atomicWriteIORef',
atomicModifyIORef_, atomicModifyIORef'_
) where
import Data.IORef
import Control.Exception
writeIORef' :: IORef a -> a -> IO ()
writeIORef' :: IORef a -> a -> IO ()
writeIORef' IORef a
ref a
x = do
a -> IO a
forall a. a -> IO a
evaluate a
x
IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef a
ref a
x
atomicWriteIORef' :: IORef a -> a -> IO ()
atomicWriteIORef' :: IORef a -> a -> IO ()
atomicWriteIORef' IORef a
ref a
x = do
a -> IO a
forall a. a -> IO a
evaluate a
x
IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
atomicWriteIORef IORef a
ref a
x
atomicModifyIORef_ :: IORef a -> (a -> a) -> IO ()
atomicModifyIORef_ :: IORef a -> (a -> a) -> IO ()
atomicModifyIORef_ IORef a
r a -> a
f = IORef a -> (a -> (a, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef IORef a
r ((a -> (a, ())) -> IO ()) -> (a -> (a, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a
v -> (a -> a
f a
v, ())
atomicModifyIORef'_ :: IORef a -> (a -> a) -> IO ()
atomicModifyIORef'_ :: IORef a -> (a -> a) -> IO ()
atomicModifyIORef'_ IORef a
r a -> a
f = IORef a -> (a -> (a, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef a
r ((a -> (a, ())) -> IO ()) -> (a -> (a, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a
v -> (a -> a
f a
v, ())