some re-arrangement for the benefit of Hugs.
#ifdef __HUGS__
import Hugs.ST
+import qualified Hugs.LazyST as LazyST
+
+fixST :: (a -> ST s a) -> ST s a
+fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
+
+unsafeInterleaveST :: ST s a -> ST s a
+unsafeInterleaveST =
+ LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
#endif
#ifdef __GLASGOW_HASKELL__
RealWorld,
stToIO,
-#ifndef __HUGS__
-- * Converting between strict and lazy 'ST'
strictToLazyST, lazyToStrictST
-#endif
) where
import Prelude
import Control.Monad.Fix
-#ifdef __GLASGOW_HASKELL__
+import Control.Monad.ST (RealWorld)
import qualified Control.Monad.ST as ST
+
+#ifdef __GLASGOW_HASKELL__
import qualified GHC.ST
import GHC.Base
import Control.Monad
unsafeInterleaveST :: ST s a -> ST s a
unsafeInterleaveST = strictToLazyST . ST.unsafeInterleaveST . lazyToStrictST
+#endif
unsafeIOToST :: IO a -> ST s a
unsafeIOToST = strictToLazyST . ST.unsafeIOToST
stToIO :: ST RealWorld a -> IO a
stToIO = ST.stToIO . lazyToStrictST
-#endif
import Prelude
#ifdef __GLASGOW_HASKELL__
+import GHC.ST
import GHC.STRef
#endif
#include "Dynamic.h"
INSTANCE_TYPEABLE2(STRef,stRefTc,"STRef")
+
+-- |Mutate the contents of an 'STRef'
+modifySTRef :: STRef s a -> (a -> a) -> ST s ()
+modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref
) where
import Control.Monad.ST.Lazy
-#ifdef __HUGS__
-import Hugs.LazyST as ST
-#else
import qualified Data.STRef as ST
import qualified Control.Monad.ST as ST
readSTRef = strictToLazyST . ST.readSTRef
writeSTRef r a = strictToLazyST (ST.writeSTRef r a)
modifySTRef r f = strictToLazyST (ST.modifySTRef r f)
-
-#endif /* __HUGS__ */
case writeMutVar# var# val s1# of { s2# ->
(# s2#, () #) }
--- |Mutate the contents of an 'STRef'
-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#