GHC.IORef

base-4.14.2.0: Basic libraries

Copyright | (c) The University of Glasgow 2008
License | see libraries/base/LICENSE
Maintainer | cvs-ghc@haskell.org
Stability | internal
Portability | non-portable (GHC Extensions)
Safe Haskell | Unsafe
Language | Haskell2010

GHC.IORef

Description

The IORef type

Synopsis

- newtype IORef a = IORef (STRef RealWorld a)
- newIORef :: a -> IO (IORef a)
- readIORef :: IORef a -> IO a
- writeIORef :: IORef a -> a -> IO ()
- atomicModifyIORef2Lazy :: IORef a -> (a -> (a, b)) -> IO (a, (a, b))
- atomicModifyIORef2 :: IORef a -> (a -> (a, b)) -> IO (a, (a, b))
- atomicModifyIORefLazy_ :: IORef a -> (a -> a) -> IO (a, a)
- atomicModifyIORef'_ :: IORef a -> (a -> a) -> IO (a, a)
- atomicModifyIORefP :: IORef a -> (a -> (a, b)) -> IO b
- atomicSwapIORef :: IORef a -> a -> IO a
- atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b

# Documentation

newtype IORef a Source #

A mutable variable in the `IO` monad

Constructors

IORef (STRef RealWorld a) |

#### Instances

Instances details

Eq (IORef a) # | Pointer equality. Since: base-4.0.0.0
Instance details Defined in GHC.IORef Methods (==) :: IORef a -> IORef a -> Bool Source # (/=) :: IORef a -> IORef a -> Bool Source #

newIORef :: a -> IO (IORef a) Source #

Build a new `IORef`

readIORef :: IORef a -> IO a Source #

Read the value of an `IORef`

writeIORef :: IORef a -> a -> IO () Source #

Write a new value into an `IORef`

atomicModifyIORef2Lazy :: IORef a -> (a -> (a, b)) -> IO (a, (a, b)) Source #

atomicModifyIORef2 :: IORef a -> (a -> (a, b)) -> IO (a, (a, b)) Source #

atomicModifyIORefLazy_ :: IORef a -> (a -> a) -> IO (a, a) Source #

Atomically apply a function to the contents of an `IORef` and return the old and new values. The result of the function is not forced. As this can lead to a memory leak, it is usually better to use `atomicModifyIORef'_`.

atomicModifyIORef'_ :: IORef a -> (a -> a) -> IO (a, a) Source #

Atomically apply a function to the contents of an `IORef` and return the old and new values. The result of the function is forced.

atomicModifyIORefP :: IORef a -> (a -> (a, b)) -> IO b Source #

A version of `atomicModifyIORef` that forces the (pair) result of the function.

atomicSwapIORef :: IORef a -> a -> IO a Source #

Atomically replace the contents of an `IORef`, returning the old contents.

atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b Source #

Strict version of `atomicModifyIORef`. This forces both the value stored in the `IORef` and the value returned. The new value is installed in the `IORef` before the returned value is forced. So

    atomicModifyIORef' ref (x -> (x+1, undefined))

will increment the `IORef` and then throw an exception in the calling thread.

Since: base-4.6.0.0