Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Data.StateRef.Instances
Contents
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.
Documentation
A mutable variable in the IO
monad
Instances
Eq (IORef a) | ^ Pointer equality. Since: base-4.1.0.0 |
MonadIO m => NewRef (IORef a) m a # | |
Defined in Data.StateRef.Instances Methods newReference :: a -> m (IORef a) # | |
MonadIO m => ModifyRef (IORef a) m a # | |
Defined in Data.StateRef.Instances Methods atomicModifyReference :: IORef a -> (a -> (a, b)) -> m b # modifyReference :: IORef a -> (a -> a) -> m () # | |
MonadIO m => ReadRef (IORef a) m a # | |
Defined in Data.StateRef.Instances Methods readReference :: IORef a -> m a # | |
MonadIO m => WriteRef (IORef a) m a # | |
Defined in Data.StateRef.Instances Methods writeReference :: IORef a -> a -> m () # |
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
Eq (MVar a) | Since: base-4.1.0.0 |
MonadIO m => PutMRef (MVar a) m a # | |
Defined in Data.MRef.Instances Methods putMReference :: MVar a -> a -> m () # | |
MonadIO m => TakeMRef (MVar a) m a # | |
Defined in Data.MRef.Instances Methods takeMReference :: MVar a -> m a # | |
MonadIO m => NewMRef (MVar a) m a # | |
Defined in Data.MRef.Instances | |
MonadIO m => NewRef (MVar a) m (Maybe a) # | |
Defined in Data.StateRef.Instances Methods newReference :: Maybe a -> m (MVar a) # |
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
The strict state-transformer monad.
A computation of type
transforms an internal state indexed
by ST
s as
, and returns a value of type a
.
The s
parameter is either
- an uninstantiated type variable (inside invocations of
runST
), or RealWorld
(inside invocations ofstToIO
).
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
Monad (ST s) | Since: base-2.1 |
Functor (ST s) | Since: base-2.1 |
MonadFail (ST s) | Since: base-4.11.0.0 |
Applicative (ST s) | Since: base-4.4.0.0 |
HasRef (ST s) # | |
Show (ST s a) | Since: base-2.1 |
Semigroup a => Semigroup (ST s a) | Since: base-4.11.0.0 |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
Monad m => NewRef (ST s a) m a # | |
Defined in Data.StateRef.Instances Methods newReference :: a -> m (ST s a) # | |
MonadIO m => ReadRef (ST RealWorld a) m a # | |
Defined in Data.StateRef.Instances Methods readReference :: ST RealWorld a -> m a # | |
NewRef (STRef s a) (ST s) a # | |
Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) # | |
ModifyRef (STRef s a) (ST s) a # | |
Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b # modifyReference :: STRef s a -> (a -> a) -> ST s () # | |
ReadRef (ST s a) (ST s) a # | |
Defined in Data.StateRef.Instances Methods readReference :: ST s a -> ST s a # | |
ReadRef (STRef s a) (ST s) a # | |
Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a # | |
WriteRef (STRef s a) (ST s) a # | |
Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () # |
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
NewRef (STRef RealWorld a) IO a # | |
Defined in Data.StateRef.Instances Methods newReference :: a -> IO (STRef RealWorld a) # | |
ModifyRef (STRef RealWorld a) IO a # | |
Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () # | |
MonadIO m => ReadRef (ST RealWorld a) m a # | |
Defined in Data.StateRef.Instances Methods readReference :: ST RealWorld a -> m a # | |
ReadRef (STRef RealWorld a) IO a # | |
Defined in Data.StateRef.Instances Methods readReference :: STRef RealWorld a -> IO a # | |
WriteRef (STRef RealWorld a) IO a # | |
Defined in Data.StateRef.Instances Methods writeReference :: STRef RealWorld a -> a -> IO () # |
data ForeignPtr a #
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
A monad supporting atomic memory transactions.
Instances
Shared memory locations that support atomic memory transactions.
Instances
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
atomically :: STM a -> IO a #
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.
newtype UnsafeModifyRef sr #
Wrap a state reference that supports reading and writing, and add a
potentially thread-unsafe ModifyRef
instance.
Constructors
UnsafeModifyRef sr |
Instances
(Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a # | |
Defined in Data.StateRef.Instances.Undecidable Methods atomicModifyReference :: UnsafeModifyRef sr -> (a -> (a, b)) -> m b # modifyReference :: UnsafeModifyRef sr -> (a -> a) -> m () # | |
ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a # | |
Defined in Data.StateRef.Instances.Undecidable Methods readReference :: UnsafeModifyRef sr -> m a # | |
WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a # | |
Defined in Data.StateRef.Instances.Undecidable Methods writeReference :: UnsafeModifyRef sr -> a -> m () # |
Orphan instances
HasRef IO # | |
HasRef (ST s) # | |
HasRef (ST s) # | |
Monad m => NewRef (IO a) m a # | |
Methods newReference :: a -> m (IO a) # | |
(Storable a, MonadIO m) => NewRef (ForeignPtr a) m a # | |
Methods newReference :: a -> m (ForeignPtr a) # | |
MonadIO m => NewRef (IORef a) m a # | |
Methods newReference :: a -> m (IORef a) # | |
(Storable a, MonadIO m) => ModifyRef (ForeignPtr a) m a # | |
Methods atomicModifyReference :: ForeignPtr a -> (a -> (a, b)) -> m b # modifyReference :: ForeignPtr a -> (a -> a) -> m () # | |
MonadIO m => ModifyRef (IORef a) m a # | |
Methods atomicModifyReference :: IORef a -> (a -> (a, b)) -> m b # modifyReference :: IORef a -> (a -> a) -> m () # | |
MonadIO m => ReadRef (IO a) m a # | |
Methods readReference :: IO a -> m a # | |
(Storable a, MonadIO m) => ReadRef (ForeignPtr a) m a # | |
Methods readReference :: ForeignPtr a -> m a # | |
MonadIO m => ReadRef (IORef a) m a # | |
Methods readReference :: IORef a -> m a # | |
(Storable a, MonadIO m) => WriteRef (ForeignPtr a) m a # | |
Methods writeReference :: ForeignPtr a -> a -> m () # | |
MonadIO m => WriteRef (IORef a) m a # | |
Methods writeReference :: IORef a -> a -> m () # | |
MonadIO m => NewRef (MVar a) m (Maybe a) # | |
Methods newReference :: Maybe a -> m (MVar a) # | |
Monad m => NewRef (ST s a) m a # | |
Methods newReference :: a -> m (ST s a) # | |
NewRef (STRef RealWorld a) IO a # | |
Methods newReference :: a -> IO (STRef RealWorld a) # | |
HasRef m => NewRef (Ref m a) m a # | |
Methods newReference :: a -> m (Ref m a) # | |
ModifyRef (STRef RealWorld a) IO a # | |
Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () # | |
ModifyRef (Ref m a) m a # | |
Methods atomicModifyReference :: Ref m a -> (a -> (a, b)) -> m b # modifyReference :: Ref m a -> (a -> a) -> m () # | |
MonadIO m => ReadRef (ST RealWorld a) m a # | |
Methods readReference :: ST RealWorld a -> m a # | |
ReadRef (STRef RealWorld a) IO a # | |
Methods readReference :: STRef RealWorld a -> IO a # | |
ReadRef (Ref m a) m a # | |
Methods readReference :: Ref m a -> m a # | |
WriteRef (STRef RealWorld a) IO a # | |
Methods writeReference :: STRef RealWorld a -> a -> IO () # | |
WriteRef (Ref m a) m a # | |
Methods writeReference :: Ref m a -> a -> m () # | |
NewRef (STRef s a) (ST s) a # | |
Methods newReference :: a -> ST s (STRef s a) # | |
NewRef (STRef s a) (ST s) a # | |
Methods newReference :: a -> ST s (STRef s a) # | |
ModifyRef (STRef s a) (ST s) a # | |
Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b # modifyReference :: STRef s a -> (a -> a) -> ST s () # | |
ModifyRef (STRef s a) (ST s) a # | |
Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b # modifyReference :: STRef s a -> (a -> a) -> ST s () # | |
ReadRef (ST s a) (ST s) a # | |
Methods readReference :: ST s a -> ST s a # | |
ReadRef (STRef s a) (ST s) a # | |
Methods readReference :: STRef s a -> ST s a # | |
ReadRef (STRef s a) (ST s) a # | |
Methods readReference :: STRef s a -> ST s a # | |
WriteRef (STRef s a) (ST s) a # | |
Methods writeReference :: STRef s a -> a -> ST s () # | |
WriteRef (STRef s a) (ST s) a # | |
Methods writeReference :: STRef s a -> a -> ST s () # |