add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / Data / STRef.hs
1 {-# LANGUAGE CPP #-}
2
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module      :  Data.STRef
6 -- Copyright   :  (c) The University of Glasgow 2001
7 -- License     :  BSD-style (see the file libraries/base/LICENSE)
8 -- 
9 -- Maintainer  :  libraries@haskell.org
10 -- Stability   :  experimental
11 -- Portability :  non-portable (uses Control.Monad.ST)
12 --
13 -- Mutable references in the (strict) ST monad.
14 --
15 -----------------------------------------------------------------------------
16
17 module Data.STRef (
18         -- * STRefs
19         STRef,          -- abstract, instance Eq
20         newSTRef,       -- :: a -> ST s (STRef s a)
21         readSTRef,      -- :: STRef s a -> ST s a
22         writeSTRef,     -- :: STRef s a -> a -> ST s ()
23         modifySTRef     -- :: STRef s a -> (a -> a) -> ST s ()
24  ) where
25
26 import Prelude
27
28 #ifdef __GLASGOW_HASKELL__
29 import GHC.ST
30 import GHC.STRef
31 #endif
32
33 #ifdef __HUGS__
34 import Hugs.ST
35 import Data.Typeable
36
37 #include "Typeable.h"
38 INSTANCE_TYPEABLE2(STRef,stRefTc,"STRef")
39 #endif
40
41 -- |Mutate the contents of an 'STRef'
42 modifySTRef :: STRef s a -> (a -> a) -> ST s ()
43 modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref