GHC.STRef

base-4.14.2.0: Basic libraries

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

GHC.STRef

Description

References in the `ST` monad.

Synopsis

- data STRef s a = STRef (MutVar# s a)
- newSTRef :: a -> ST s (STRef s a)
- readSTRef :: STRef s a -> ST s a
- writeSTRef :: STRef s a -> a -> ST s ()

# Documentation

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"

Constructors

STRef (MutVar# s a) |

#### Instances

Instances details

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

newSTRef :: a -> ST s (STRef s a) Source #

Build a new `STRef` in the current state thread

readSTRef :: STRef s a -> ST s a Source #

Read the value of an `STRef`

writeSTRef :: STRef s a -> a -> ST s () Source #

Write a new value into an `STRef`