d261cbf9d2abdba59001751130af5d9eb7f5f704
[packages/old-time.git] / Data / STRef.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : Data.STRef
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable (requires non-portable module ST)
10 --
11 -- Mutable references in the (strict) ST monad.
12 --
13 -----------------------------------------------------------------------------
14
15 module Data.STRef (
16 -- * STRefs
17 STRef, -- abstract, instance Eq
18 newSTRef, -- :: a -> ST s (STRef s a)
19 readSTRef, -- :: STRef s a -> ST s a
20 writeSTRef, -- :: STRef s a -> a -> ST s ()
21 modifySTRef -- :: STRef s a -> (a -> a) -> ST s ()
22 ) where
23
24 import Prelude
25
26 #ifdef __GLASGOW_HASKELL__
27 import GHC.ST
28 import GHC.STRef
29 #endif
30
31 #ifdef __HUGS__
32 import Hugs.ST
33 #endif
34
35 -- |Mutate the contents of an 'STRef'
36 modifySTRef :: STRef s a -> (a -> a) -> ST s ()
37 modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref