From b050a63d0142fc351e4618e378047790109e5199 Mon Sep 17 00:00:00 2001 From: sof Date: Sat, 23 Jan 1999 17:46:01 +0000 Subject: [PATCH] [project @ 1999-01-23 17:46:01 by sof] Move ST <--> IO coercion functions from IOExts to (Lazy)?ST --- ghc/lib/exts/IOExts.lhs | 14 -------------- ghc/lib/exts/LazyST.lhs | 3 +++ ghc/lib/exts/ST.lhs | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ghc/lib/exts/IOExts.lhs b/ghc/lib/exts/IOExts.lhs index 5bbd8f0..612b37d 100644 --- a/ghc/lib/exts/IOExts.lhs +++ b/ghc/lib/exts/IOExts.lhs @@ -48,8 +48,6 @@ module IOExts #endif , unsafePtrEq - , unsafeIOToST - , stToIO ) where @@ -161,18 +159,6 @@ trace string expr = unsafePerformIO $ do #endif \end{code} -\begin{code} -unsafeIOToST :: IO a -> ST s a -#ifdef __HUGS__ -unsafeIOToST = primUnsafeCoerce -#else -unsafeIOToST (IO io) = ST $ \ s -> - case ((unsafeCoerce# io) s) of - (# new_s, a #) -> unsafeCoerce# (STret new_s a) --- IOfail new_s e -> error ("I/O Error (unsafeIOToST): " ++ showsPrec 0 e "\n") -#endif -\end{code} - Not something you want to call normally, but useful in the cases where you do want to flush stuff out of the heap or make sure you've got room enough diff --git a/ghc/lib/exts/LazyST.lhs b/ghc/lib/exts/LazyST.lhs index 07bf7a7..ee3925e 100644 --- a/ghc/lib/exts/LazyST.lhs +++ b/ghc/lib/exts/LazyST.lhs @@ -26,6 +26,8 @@ module LazyST ( thawSTArray, freezeSTArray, unsafeFreezeSTArray, Ix, + ST.unsafeIOToST, ST.stToIO, + strictToLazyST, lazyToStrictST ) where @@ -80,6 +82,7 @@ writeSTRef :: ST.STRef s a -> a -> ST s () newSTRef = strictToLazyST . ST.newSTRef readSTRef = strictToLazyST . ST.readSTRef writeSTRef r a = strictToLazyST (ST.writeSTRef r a) + \end{code} %********************************************************* diff --git a/ghc/lib/exts/ST.lhs b/ghc/lib/exts/ST.lhs index 5a52131..e7d6fc8 100644 --- a/ghc/lib/exts/ST.lhs +++ b/ghc/lib/exts/ST.lhs @@ -21,6 +21,8 @@ module ST ( STRef, newSTRef, readSTRef, writeSTRef, + unsafeIOToST, stToIO, + STArray, newSTArray, readSTArray, writeSTArray, boundsSTArray, thawSTArray, freezeSTArray, unsafeFreezeSTArray, @@ -37,7 +39,8 @@ import PreludeBuiltin #else import PrelArr import PrelST -import PrelBase ( Eq(..), Int, Bool, ($), ()(..) ) +import PrelBase ( Eq(..), Int, Bool, ($), ()(..), unsafeCoerce# ) +import PrelIOBase ( IO(..), stToIO ) #endif import Monad import Ix @@ -149,3 +152,15 @@ unsafeFreezeSTArray (STArray arr) = unsafeFreezeArray arr #endif \end{code} + +\begin{code} +unsafeIOToST :: IO a -> ST s a +#ifdef __HUGS__ +unsafeIOToST = primUnsafeCoerce +#else +unsafeIOToST (IO io) = ST $ \ s -> + case ((unsafeCoerce# io) s) of + (# new_s, a #) -> unsafeCoerce# (STret new_s a) +-- IOfail new_s e -> error ("I/O Error (unsafeIOToST): " ++ showsPrec 0 e "\n") +#endif +\end{code} -- 1.7.10.4