Data.IORef.Lifted

lifted-base-0.2.3.12: lifted IO operations from the base library

Copyright | Liyang HU Bas van Dijk
License | BSD-style
Maintainer | Bas van Dijk <v.dijk.bas@gmail.com>
Stability | experimental
Safe Haskell | Safe
Language | Haskell98

Data.IORef.Lifted

Description

This is a wrapped version of Data.IORef with types generalised from `IO` to all monads in `MonadBase`.

Synopsis

- data IORef a
- newIORef :: MonadBase IO m => a -> m (IORef a)
- readIORef :: MonadBase IO m => IORef a -> m a
- writeIORef :: MonadBase IO m => IORef a -> a -> m ()
- modifyIORef :: MonadBase IO m => IORef a -> (a -> a) -> m ()
- modifyIORef' :: MonadBase IO m => IORef a -> (a -> a) -> m ()
- atomicModifyIORef :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
- atomicModifyIORef' :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
- atomicWriteIORef :: MonadBase IO m => IORef a -> a -> m ()
- mkWeakIORef :: MonadBaseControl IO m => IORef a -> m () -> m (Weak (IORef a))

# Documentation

data IORef a #

A mutable variable in the `IO` monad.

    >>> import GHC.Internal.Data.IORef
    >>> r <- newIORef 0
    >>> readIORef r
    0
    >>> writeIORef r 1
    >>> readIORef r
    1
    >>> atomicWriteIORef r 2
    >>> readIORef r
    2
    >>> modifyIORef' r (+ 1)
    >>> readIORef r
    3
    >>> atomicModifyIORef' r (\a -> (a + 1, ()))
    >>> readIORef r
    4

See also `STRef` and `MVar`.

#### Instances

Instances details

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

newIORef :: MonadBase IO m => a -> m (IORef a) #

Generalized version of `newIORef`.

readIORef :: MonadBase IO m => IORef a -> m a #

Generalized version of `readIORef`.

writeIORef :: MonadBase IO m => IORef a -> a -> m () #

Generalized version of `writeIORef`.

modifyIORef :: MonadBase IO m => IORef a -> (a -> a) -> m () #

Generalized version of `modifyIORef`.

modifyIORef' :: MonadBase IO m => IORef a -> (a -> a) -> m () #

Generalized version of `modifyIORef'`.

atomicModifyIORef :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b #

Generalized version of `atomicModifyIORef`.

atomicModifyIORef' :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b #

Generalized version of `atomicModifyIORef'`.

atomicWriteIORef :: MonadBase IO m => IORef a -> a -> m () #

Generalized version of `atomicWriteIORef`.

mkWeakIORef :: MonadBaseControl IO m => IORef a -> m () -> m (Weak (IORef a)) #

Generalized version of `mkWeakIORef`.

Note any monadic side effects in `m` of the "finalizer" computation are discarded.