a13bc5682f55f075562dcb06e95e5ac92a99e825
[ghc-base.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 import Data.Dynamic
36
37 #include "Typeable.h"
38 INSTANCE_TYPEABLE2(STRef,stRefTc,"STRef")
39
40 -- |Mutate the contents of an 'STRef'
41 modifySTRef :: STRef s a -> (a -> a) -> ST s ()
42 modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref