stateref-0.3: Abstraction for things that work like IORef.

Safe Haskell | Safe-Inferred
Language | Haskell98

Data.StateRef.Instances

Contents

- Orphan instances

Description

This module exports no new symbols of its own. It defines several basic class instances for creating, reading, and writing standard reference types, and re-exports the types for which it defines instances.

TODO: add millions of SPECIALIZE INSTANCE pragmas, for IO monad at a minimum.

Synopsis

- data IORef a
- data MVar a
- class Monad m => MonadIO (m :: Type -> Type) where
  - liftIO :: IO a -> m a
- data STRef s a
- data ST s a
- data RealWorld
- data ForeignPtr a
- data TVar a
- data STM a
- atomically :: STM a -> IO a
- data TMVar a
- newtype UnsafeModifyRef sr = UnsafeModifyRef sr

# Documentation

data IORef a Source #

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 Source # (/=) :: IORef a -> IORef a -> Bool Source #
MonadIO m => ModifyRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: IORef a -> (a -> (a, b)) -> m b Source # modifyReference :: IORef a -> (a -> a) -> m () Source #
MonadIO m => NewRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (IORef a) Source #
MonadIO m => ReadRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: IORef a -> m a Source #
MonadIO m => WriteRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: IORef a -> a -> m () Source #

data MVar a Source #

An `MVar` (pronounced "em-var") is a synchronising variable, used for communication between concurrent threads. It can be thought of as a box, which may be empty or full.

#### Instances

Instances details

Eq (MVar a) | Compares the underlying pointers. Since: base-4.1.0.0
Instance details Defined in GHC.Internal.MVar Methods (==) :: MVar a -> MVar a -> Bool Source # (/=) :: MVar a -> MVar a -> Bool Source #
MonadIO m => NewMRef (MVar a) m a Source # |
Instance details Defined in Data.MRef.Instances Methods newMReference :: a -> m (MVar a) Source # newEmptyMReference :: m (MVar a) Source #
MonadIO m => PutMRef (MVar a) m a Source # |
Instance details Defined in Data.MRef.Instances Methods putMReference :: MVar a -> a -> m () Source #
MonadIO m => TakeMRef (MVar a) m a Source # |
Instance details Defined in Data.MRef.Instances Methods takeMReference :: MVar a -> m a Source #
MonadIO m => NewRef (MVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: Maybe a -> m (MVar a) Source #

class Monad m => MonadIO (m :: Type -> Type) where Source #

Monads in which `IO` computations may be embedded. Any monad built by applying a sequence of monad transformers to the `IO` monad will be an instance of this class.

Instances should satisfy the following laws, which state that `liftIO` is a transformer of monads:

-     liftIO . return = return

-     liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Methods

liftIO :: IO a -> m a Source #

Lift a computation from the `IO` monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. `IO` is the base monad for the stack).

### Example

Expand

    import Control.Monad.Trans.State -- from the "transformers" library

    printState :: Show s => StateT s IO ()
    printState = do
      state <- get
      liftIO $ print state

Had we omitted ``liftIO``, we would have ended up with this error:

    • Couldn't match type ‘IO’ with ‘StateT s IO’
     Expected type: StateT s IO ()
       Actual type: IO ()

The important part here is the mismatch between `StateT s IO ()` and ``IO` ()`.

Luckily, we know of a function that takes an ``IO` a` and returns an `(m a)`: ``liftIO``, enabling us to run the program and see the expected results:

    > evalStateT printState "hello"
    "hello"

    > evalStateT printState 3
    3

#### Instances

Instances details

MonadIO IO | Since: base-4.9.0.0
Instance details Defined in Control.Monad.IO.Class Methods liftIO :: IO a -> IO a Source #

data STRef s a Source #

a value of type `STRef s a` is a mutable variable in state thread `s`, containing a value of type `a`

    >>> :{
    runST (do
        ref <- newSTRef "hello"
        x <- readSTRef ref
        writeSTRef ref (x ++ "world")
        readSTRef ref )
    :}
    "helloworld"

#### Instances

Instances details

Eq (STRef s a) | Pointer equality. Since: base-2.1
Instance details Defined in GHC.Internal.STRef Methods (==) :: STRef s a -> STRef s a -> Bool Source # (/=) :: STRef s a -> STRef s a -> Bool Source #
ModifyRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b Source # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () Source #
NewRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> IO (STRef RealWorld a) Source #
ReadRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef RealWorld a -> IO a Source #
WriteRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef RealWorld a -> a -> IO () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () Source #

data ST s a Source #

The strict `ST` monad. The `ST` monad allows for destructive updates, but is escapable (unlike IO). A computation of type ``ST` s a` returns a value of type `a`, and execute in "thread" `s`. The `s` parameter is either

- an uninstantiated type variable (inside invocations of `runST`), or
- `RealWorld` (inside invocations of `stToIO`).

It serves to keep the internal states of different invocations of `runST` separate from each other and from invocations of `stToIO`.

The `>>=` and `>>` operations are strict in the state (though not in values stored in the state). For example,

    runST (writeSTRef _|_ v >>= f) = _|_

#### Instances

Instances details

Applicative (ST s) | Since: base-4.4.0.0
Instance details Defined in GHC.Internal.ST Methods pure :: a -> ST s a Source # (<*>) :: ST s (a -> b) -> ST s a -> ST s b Source # liftA2 :: (a -> b -> c) -> ST s a -> ST s b -> ST s c Source # (*>) :: ST s a -> ST s b -> ST s b Source # (<*) :: ST s a -> ST s b -> ST s a Source #
Functor (ST s) | Since: base-2.1
Instance details Defined in GHC.Internal.ST Methods fmap :: (a -> b) -> ST s a -> ST s b Source # (<$) :: a -> ST s b -> ST s a Source #
Monad (ST s) | Since: base-2.1
Instance details Defined in GHC.Internal.ST Methods (>>=) :: ST s a -> (a -> ST s b) -> ST s b Source # (>>) :: ST s a -> ST s b -> ST s b Source # return :: a -> ST s a Source #
HasRef (ST s) Source # |
Instance details Defined in Data.StateRef.Instances Methods newRef :: a -> ST s (Ref (ST s) a) Source #
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0
Instance details Defined in GHC.Internal.ST Methods mempty :: ST s a Source # mappend :: ST s a -> ST s a -> ST s a Source # mconcat :: [ST s a] -> ST s a Source #
Semigroup a => Semigroup (ST s a) | Since: base-4.11.0.0
Instance details Defined in GHC.Internal.ST Methods (<>) :: ST s a -> ST s a -> ST s a Source # sconcat :: NonEmpty (ST s a) -> ST s a Source # stimes :: Integral b => b -> ST s a -> ST s a Source #
Show (ST s a) | Since: base-2.1
Instance details Defined in GHC.Internal.ST Methods showsPrec :: Int -> ST s a -> ShowS Source # show :: ST s a -> String Source # showList :: [ST s a] -> ShowS Source #
Monad m => NewRef (ST s a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (ST s a) Source #
MonadIO m => ReadRef (ST RealWorld a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ST RealWorld a -> m a Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) Source #
ReadRef (ST s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ST s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () Source #

data RealWorld Source #

`RealWorld` is deeply magical. It is primitive, but it is not unlifted (hence `ptrArg`). We never manipulate values of type `RealWorld`; it's only used in the type system, to parameterise `State#`.

#### Instances

Instances details

ModifyRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b Source # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () Source #
NewRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> IO (STRef RealWorld a) Source #
MonadIO m => ReadRef (ST RealWorld a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ST RealWorld a -> m a Source #
ReadRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef RealWorld a -> IO a Source #
WriteRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef RealWorld a -> a -> IO () Source #

data ForeignPtr a Source #

The type `ForeignPtr` represents references to objects that are maintained in a foreign language, i.e., that are not part of the data structures usually managed by the Haskell storage manager. The essential difference between `ForeignPtr`s and vanilla memory references of type `Ptr a` is that the former may be associated with finalizers. A finalizer is a routine that is invoked when the Haskell storage manager detects that - within the Haskell heap and stack - there are no more references left that are pointing to the `ForeignPtr`. Typically, the finalizer will, then, invoke routines in the foreign language that free the resources bound by the foreign object.

The `ForeignPtr` is parameterised in the same way as `Ptr`. The type argument of `ForeignPtr` should normally be an instance of class `Storable`.

#### Instances

Instances details

Show (ForeignPtr a) | Since: base-2.1
Instance details Defined in GHC.Internal.ForeignPtr Methods showsPrec :: Int -> ForeignPtr a -> ShowS Source # show :: ForeignPtr a -> String Source # showList :: [ForeignPtr a] -> ShowS Source #
Eq (ForeignPtr a) | Since: base-2.1
Instance details Defined in GHC.Internal.ForeignPtr Methods (==) :: ForeignPtr a -> ForeignPtr a -> Bool Source # (/=) :: ForeignPtr a -> ForeignPtr a -> Bool Source #
Ord (ForeignPtr a) | Since: base-2.1

Instance details

Defined in GHC.Internal.ForeignPtr

Methods

compare :: ForeignPtr a -> ForeignPtr a -> Ordering Source #

(<) :: ForeignPtr a -> ForeignPtr a -> Bool Source #

(<=) :: ForeignPtr a -> ForeignPtr a -> Bool Source #

(>) :: ForeignPtr a -> ForeignPtr a -> Bool Source #

(>=) :: ForeignPtr a -> ForeignPtr a -> Bool Source #

max :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a Source #

min :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a Source #

(Storable a, MonadIO m) => ModifyRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: ForeignPtr a -> (a -> (a, b)) -> m b Source # modifyReference :: ForeignPtr a -> (a -> a) -> m () Source #
(Storable a, MonadIO m) => NewRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (ForeignPtr a) Source #
(Storable a, MonadIO m) => ReadRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ForeignPtr a -> m a Source #
(Storable a, MonadIO m) => WriteRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: ForeignPtr a -> a -> m () Source #

data TVar a Source #

Shared memory locations that support atomic memory transactions.

#### Instances

Instances details

Eq (TVar a) | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods (==) :: TVar a -> TVar a -> Bool Source # (/=) :: TVar a -> TVar a -> Bool Source #
NewMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> STM (TVar (Maybe a)) Source # newEmptyMReference :: STM (TVar (Maybe a)) Source #
NewMRef (TVar (Maybe a)) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> IO (TVar (Maybe a)) Source # newEmptyMReference :: IO (TVar (Maybe a)) Source #
PutMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TVar (Maybe a) -> a -> STM () Source #
PutMRef (TVar (Maybe a)) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TVar (Maybe a) -> a -> IO () Source #
TakeMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TVar (Maybe a) -> STM a Source #
TakeMRef (TVar (Maybe a)) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TVar (Maybe a) -> IO a Source #
ModifyRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: TVar a -> (a -> (a, b)) -> STM b Source # modifyReference :: TVar a -> (a -> a) -> STM () Source #
MonadIO m => ModifyRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: TVar a -> (a -> (a, b)) -> m b Source # modifyReference :: TVar a -> (a -> a) -> m () Source #
NewRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> STM (TVar a) Source #
MonadIO m => NewRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> m (TVar a) Source #
ReadRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TVar a -> STM a Source #
MonadIO m => ReadRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TVar a -> m a Source #
WriteRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: TVar a -> a -> STM () Source #
MonadIO m => WriteRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: TVar a -> a -> m () Source #

data STM a Source #

A monad supporting atomic memory transactions.

#### Instances

Instances details

Alternative STM | Takes the first non-`retry`ing `STM` action. Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods empty :: STM a Source # (<|>) :: STM a -> STM a -> STM a Source # some :: STM a -> STM [a] Source # many :: STM a -> STM [a] Source #
Applicative STM | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods pure :: a -> STM a Source # (<*>) :: STM (a -> b) -> STM a -> STM b Source # liftA2 :: (a -> b -> c) -> STM a -> STM b -> STM c Source # (*>) :: STM a -> STM b -> STM b Source # (<*) :: STM a -> STM b -> STM a Source #
Functor STM | Since: base-4.3.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods fmap :: (a -> b) -> STM a -> STM b Source # (<$) :: a -> STM b -> STM a Source #
Monad STM | Since: base-4.3.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods (>>=) :: STM a -> (a -> STM b) -> STM b Source # (>>) :: STM a -> STM b -> STM b Source # return :: a -> STM a Source #
MonadPlus STM | Takes the first non-`retry`ing `STM` action. Since: base-4.3.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods mzero :: STM a Source # mplus :: STM a -> STM a -> STM a Source #
MonadFix STM | Since: stm-2.3
Instance details Defined in Control.Monad.STM Methods mfix :: (a -> STM a) -> STM a Source #
HasMRef STM Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMRef :: a -> STM (MRef STM a) Source # newEmptyMRef :: STM (MRef STM a) Source #
HasRef STM Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newRef :: a -> STM (Ref STM a) Source #
MArray TArray e STM |

Instance details

Defined in Control.Concurrent.STM.TArray

Methods

getBounds :: Ix i => TArray i e -> STM (i, i) Source #

getNumElements :: Ix i => TArray i e -> STM Int Source #

newArray :: Ix i => (i, i) -> e -> STM (TArray i e) Source #

newArray_ :: Ix i => (i, i) -> STM (TArray i e) Source #

unsafeNewArray_ :: Ix i => (i, i) -> STM (TArray i e) Source #

unsafeRead :: Ix i => TArray i e -> Int -> STM e Source #

unsafeWrite :: Ix i => TArray i e -> Int -> e -> STM () Source #

Monoid a => Monoid (STM a) | Since: base-4.17.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods mempty :: STM a Source # mappend :: STM a -> STM a -> STM a Source # mconcat :: [STM a] -> STM a Source #
Semigroup a => Semigroup (STM a) | Since: base-4.17.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods (<>) :: STM a -> STM a -> STM a Source # sconcat :: NonEmpty (STM a) -> STM a Source # stimes :: Integral b => b -> STM a -> STM a Source #
NewMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> STM (TVar (Maybe a)) Source # newEmptyMReference :: STM (TVar (Maybe a)) Source #
NewMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> STM (TMVar a) Source # newEmptyMReference :: STM (TMVar a) Source #
PutMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TVar (Maybe a) -> a -> STM () Source #
PutMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TMVar a -> a -> STM () Source #
TakeMRef (TVar (Maybe a)) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TVar (Maybe a) -> STM a Source #
TakeMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TMVar a -> STM a Source #
ModifyRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: TVar a -> (a -> (a, b)) -> STM b Source # modifyReference :: TVar a -> (a -> a) -> STM () Source #
NewRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> STM (TVar a) Source #
ReadRef (STM a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: STM a -> STM a Source #
MonadIO m => ReadRef (STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: STM a -> m a Source #
ReadRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TVar a -> STM a Source #
WriteRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: TVar a -> a -> STM () Source #
NewRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: Maybe a -> STM (TMVar a) Source #
ReadRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TMVar a -> STM (Maybe a) Source #
NewMRef (MRef STM a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> IO (MRef STM a) Source # newEmptyMReference :: IO (MRef STM a) Source #
PutMRef (MRef STM a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: MRef STM a -> a -> IO () Source #
TakeMRef (MRef STM a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: MRef STM a -> IO a Source #
MonadIO m => ModifyRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: Ref STM a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref STM a -> (a -> a) -> m () Source #
MonadIO m => NewRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> m (Ref STM a) Source #
MonadIO m => ReadRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: Ref STM a -> m a Source #
MonadIO m => WriteRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: Ref STM a -> a -> m () Source #

atomically :: STM a -> IO a Source #

Perform a series of STM actions atomically.

Using `atomically` inside an `unsafePerformIO` or `unsafeInterleaveIO` subverts some of guarantees that STM provides. It makes it possible to run a transaction inside of another transaction, depending on when the thunk is evaluated. If a nested transaction is attempted, an exception is thrown by the runtime. It is possible to safely use `atomically` inside `unsafePerformIO` or `unsafeInterleaveIO`, but the typechecker does not rule out programs that may attempt nested transactions, meaning that the programmer must take special care to prevent these.

However, there are functions for creating transactional variables that can always be safely called in `unsafePerformIO`. See: `newTVarIO`, `newTChanIO`, `newBroadcastTChanIO`, `newTQueueIO`, `newTBQueueIO`, and `newTMVarIO`.

Using `unsafePerformIO` inside of `atomically` is also dangerous but for different reasons. See `unsafeIOToSTM` for more on this.

data TMVar a Source #

A `TMVar` is a synchronising variable, used for communication between concurrent threads. It can be thought of as a box, which may be empty or full.

#### Instances

Instances details

Eq (TMVar a) |
Instance details Defined in Control.Concurrent.STM.TMVar Methods (==) :: TMVar a -> TMVar a -> Bool Source # (/=) :: TMVar a -> TMVar a -> Bool Source #
NewMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> STM (TMVar a) Source # newEmptyMReference :: STM (TMVar a) Source #
NewMRef (TMVar a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods newMReference :: a -> IO (TMVar a) Source # newEmptyMReference :: IO (TMVar a) Source #
PutMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TMVar a -> a -> STM () Source #
PutMRef (TMVar a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods putMReference :: TMVar a -> a -> IO () Source #
TakeMRef (TMVar a) STM a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TMVar a -> STM a Source #
TakeMRef (TMVar a) IO a Source # |
Instance details Defined in Data.MRef.Instances.STM Methods takeMReference :: TMVar a -> IO a Source #
NewRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: Maybe a -> STM (TMVar a) Source #
MonadIO m => NewRef (TMVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: Maybe a -> m (TMVar a) Source #
ReadRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TMVar a -> STM (Maybe a) Source #
MonadIO m => ReadRef (TMVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TMVar a -> m (Maybe a) Source #

newtype UnsafeModifyRef sr Source #

Wrap a state reference that supports reading and writing, and add a potentially thread-unsafe `ModifyRef` instance.

Constructors

UnsafeModifyRef sr |

#### Instances

Instances details

(Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods atomicModifyReference :: UnsafeModifyRef sr -> (a -> (a, b)) -> m b Source # modifyReference :: UnsafeModifyRef sr -> (a -> a) -> m () Source #
ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods readReference :: UnsafeModifyRef sr -> m a Source #
WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods writeReference :: UnsafeModifyRef sr -> a -> m () Source #

# Orphan instances

HasRef IO Source # |
Instance details Methods newRef :: a -> IO (Ref IO a) Source #
HasRef (ST s) Source # |
Instance details Methods newRef :: a -> ST s (Ref (ST s) a) Source #
HasRef (ST s) Source # |
Instance details Methods newRef :: a -> ST s (Ref (ST s) a) Source #
(Storable a, MonadIO m) => ModifyRef (ForeignPtr a) m a Source # |
Instance details Methods atomicModifyReference :: ForeignPtr a -> (a -> (a, b)) -> m b Source # modifyReference :: ForeignPtr a -> (a -> a) -> m () Source #
MonadIO m => ModifyRef (IORef a) m a Source # |
Instance details Methods atomicModifyReference :: IORef a -> (a -> (a, b)) -> m b Source # modifyReference :: IORef a -> (a -> a) -> m () Source #
(Storable a, MonadIO m) => NewRef (ForeignPtr a) m a Source # |
Instance details Methods newReference :: a -> m (ForeignPtr a) Source #
MonadIO m => NewRef (IORef a) m a Source # |
Instance details Methods newReference :: a -> m (IORef a) Source #
Monad m => NewRef (IO a) m a Source # |
Instance details Methods newReference :: a -> m (IO a) Source #
(Storable a, MonadIO m) => ReadRef (ForeignPtr a) m a Source # |
Instance details Methods readReference :: ForeignPtr a -> m a Source #
MonadIO m => ReadRef (IORef a) m a Source # |
Instance details Methods readReference :: IORef a -> m a Source #
MonadIO m => ReadRef (IO a) m a Source # |
Instance details Methods readReference :: IO a -> m a Source #
(Storable a, MonadIO m) => WriteRef (ForeignPtr a) m a Source # |
Instance details Methods writeReference :: ForeignPtr a -> a -> m () Source #
MonadIO m => WriteRef (IORef a) m a Source # |
Instance details Methods writeReference :: IORef a -> a -> m () Source #
MonadIO m => NewRef (MVar a) m (Maybe a) Source # |
Instance details Methods newReference :: Maybe a -> m (MVar a) Source #
ModifyRef (STRef RealWorld a) IO a Source # |
Instance details Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b Source # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () Source #
ModifyRef (Ref m a) m a Source # |
Instance details Methods atomicModifyReference :: Ref m a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref m a -> (a -> a) -> m () Source #
Monad m => NewRef (ST s a) m a Source # |
Instance details Methods newReference :: a -> m (ST s a) Source #
NewRef (STRef RealWorld a) IO a Source # |
Instance details Methods newReference :: a -> IO (STRef RealWorld a) Source #
HasRef m => NewRef (Ref m a) m a Source # |
Instance details Methods newReference :: a -> m (Ref m a) Source #
MonadIO m => ReadRef (ST RealWorld a) m a Source # |
Instance details Methods readReference :: ST RealWorld a -> m a Source #
ReadRef (STRef RealWorld a) IO a Source # |
Instance details Methods readReference :: STRef RealWorld a -> IO a Source #
ReadRef (Ref m a) m a Source # |
Instance details Methods readReference :: Ref m a -> m a Source #
WriteRef (STRef RealWorld a) IO a Source # |
Instance details Methods writeReference :: STRef RealWorld a -> a -> IO () Source #
WriteRef (Ref m a) m a Source # |
Instance details Methods writeReference :: Ref m a -> a -> m () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Methods newReference :: a -> ST s (STRef s a) Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Methods newReference :: a -> ST s (STRef s a) Source #
ReadRef (ST s a) (ST s) a Source # |
Instance details Methods readReference :: ST s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Methods readReference :: STRef s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Methods readReference :: STRef s a -> ST s a Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Methods writeReference :: STRef s a -> a -> ST s () Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Methods writeReference :: STRef s a -> a -> ST s () Source #