X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FSTRef.lhs;h=a0dba8d080f471ce8a04e7be9f517462c6de5def;hb=d71ca65be98abb12afa1dfc2815e6e157799ffdc;hp=fa96db388975057dbf8a484aeb07e2e829e899c1;hpb=b706340c451952adf230b5b8daecad8a1f34d714;p=ghc-base.git diff --git a/GHC/STRef.lhs b/GHC/STRef.lhs index fa96db3..a0dba8d 100644 --- a/GHC/STRef.lhs +++ b/GHC/STRef.lhs @@ -1,5 +1,6 @@ \begin{code} -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -XNoImplicitPrelude #-} +{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.STRef @@ -14,29 +15,32 @@ -- ----------------------------------------------------------------------------- +-- #hide module GHC.STRef where import GHC.ST import GHC.Base data STRef s a = STRef (MutVar# s a) +-- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@, +-- containing a value of type @a@ +-- |Build a new 'STRef' in the current state thread newSTRef :: a -> ST s (STRef s a) newSTRef init = ST $ \s1# -> case newMutVar# init s1# of { (# s2#, var# #) -> (# s2#, STRef var# #) } +-- |Read the value of an 'STRef' readSTRef :: STRef s a -> ST s a readSTRef (STRef var#) = ST $ \s1# -> readMutVar# var# s1# +-- |Write a new value into an 'STRef' writeSTRef :: STRef s a -> a -> ST s () writeSTRef (STRef var#) val = ST $ \s1# -> case writeMutVar# var# val s1# of { s2# -> (# s2#, () #) } -modifySTRef :: STRef s a -> (a -> a) -> ST s () -modifySTRef ref f = readSTRef ref >>= writeSTRef ref . f - -- Just pointer equality on mutable references: instance Eq (STRef s a) where STRef v1# == STRef v2# = sameMutVar# v1# v2#