From 4ac794bfda775a2c0b03ad95506f6a415193610d Mon Sep 17 00:00:00 2001 From: ross Date: Mon, 12 May 2003 08:48:09 +0000 Subject: [PATCH] [project @ 2003-05-12 08:48:09 by ross] some re-arrangement for the benefit of Hugs. --- Control/Monad/ST.hs | 8 ++++++++ Control/Monad/ST/Lazy.hs | 8 ++++---- Data/STRef.hs | 5 +++++ Data/STRef/Lazy.hs | 5 ----- GHC/STRef.lhs | 4 ---- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Control/Monad/ST.hs b/Control/Monad/ST.hs index 7341cef..008dafc 100644 --- a/Control/Monad/ST.hs +++ b/Control/Monad/ST.hs @@ -37,6 +37,14 @@ import Data.Dynamic #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__ diff --git a/Control/Monad/ST/Lazy.hs b/Control/Monad/ST/Lazy.hs index 60ff1be..413659e 100644 --- a/Control/Monad/ST/Lazy.hs +++ b/Control/Monad/ST/Lazy.hs @@ -28,18 +28,18 @@ module Control.Monad.ST.Lazy ( 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 @@ -118,10 +118,10 @@ lazyToStrictST (ST m) = GHC.ST.ST $ \s -> 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 diff --git a/Data/STRef.hs b/Data/STRef.hs index e25e8b5..a48e29a 100644 --- a/Data/STRef.hs +++ b/Data/STRef.hs @@ -24,6 +24,7 @@ module Data.STRef ( import Prelude #ifdef __GLASGOW_HASKELL__ +import GHC.ST import GHC.STRef #endif @@ -35,3 +36,7 @@ import Data.Dynamic #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 diff --git a/Data/STRef/Lazy.hs b/Data/STRef/Lazy.hs index b05fb83..faf7de5 100644 --- a/Data/STRef/Lazy.hs +++ b/Data/STRef/Lazy.hs @@ -21,9 +21,6 @@ module Data.STRef.Lazy ( ) 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 @@ -36,5 +33,3 @@ newSTRef = strictToLazyST . ST.newSTRef readSTRef = strictToLazyST . ST.readSTRef writeSTRef r a = strictToLazyST (ST.writeSTRef r a) modifySTRef r f = strictToLazyST (ST.modifySTRef r f) - -#endif /* __HUGS__ */ diff --git a/GHC/STRef.lhs b/GHC/STRef.lhs index 5eecb85..ed56bc9 100644 --- a/GHC/STRef.lhs +++ b/GHC/STRef.lhs @@ -39,10 +39,6 @@ writeSTRef (STRef var#) val = ST $ \s1# -> 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# -- 1.7.10.4