on warp-3.2.27-conn-closed-by-pear help sign in
23 lines 782 B history raw
1{-# LANGUAGE CPP #-}
2module Control.AutoUpdate.Util
3 ( atomicModifyIORef'
4 ) where
6#ifndef MIN_VERSION_base
7#define MIN_VERSION_base(x,y,z) 1
8#endif
10#if MIN_VERSION_base(4,6,0)
11import Data.IORef (atomicModifyIORef')
12#else
13import Data.IORef (IORef, atomicModifyIORef)
14-- | Strict version of 'atomicModifyIORef'. This forces both the value stored
15-- in the 'IORef' as well as the value returned.
16atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b
17atomicModifyIORef' ref f = do
18 c <- atomicModifyIORef ref
19 (\x -> let (a, b) = f x -- Lazy application of "f"
20 in (a, a `seq` b)) -- Lazy application of "seq"
21 -- The following forces "a `seq` b", so it also forces "f x".
22 c `seq` return c
23#endif