From: sof Date: Sun, 18 May 1997 04:10:25 +0000 (+0000) Subject: [project @ 1997-05-18 04:10:25 by sof] X-Git-Tag: Approximately_1000_patches_recorded~683 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=7cf2260d5e2d5c95cfcce486fed98af6f932735b;p=ghc-hetmet.git [project @ 1997-05-18 04:10:25 by sof] Lazy ST bind and return added --- diff --git a/ghc/lib/glaExts/ST.lhs b/ghc/lib/glaExts/ST.lhs index 275b24e..e025c83 100644 --- a/ghc/lib/glaExts/ST.lhs +++ b/ghc/lib/glaExts/ST.lhs @@ -19,6 +19,8 @@ module ST ( thenST, seqST, returnST, listST, fixST, runST, unsafeInterleaveST, mapST, mapAndUnzipST, + -- the lazy variant + returnLazyST, thenLazyST, seqLazyST, MutableVar, newVar, readVar, writeVar, sameVar, @@ -81,3 +83,30 @@ sameMutableByteArray (MutableByteArray _ arr1#) (MutableByteArray _ arr2#) = sameMutableByteArray# arr1# arr2# \end{code} +Lazy monad combinators, the @Monad@ instance for @ST@ +uses the strict variant: + +\begin{code} +returnLazyST :: a -> ST s a +returnLazyST a = ST (\ s -> (a, s)) + +thenLazyST :: ST s a -> (a -> ST s b) -> ST s b +thenLazyST m k + = ST $ \ s -> + let + (ST m_a) = m + (r, new_s) = m_a s + (ST k_a) = k r + in + k_a new_s + +seqLazyST :: ST s a -> ST s b -> ST s b +seqLazyST m k + = ST $ \ s -> + let + (ST m_a) = m + (_, new_s) = m_a s + (ST k_a) = k + in + k_a new_s +\end{code}