1 -----------------------------------------------------------------------------
3 -- Module : Control.Monad.ST
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable (requires universal quantification for runST)
11 -- This library provides support for /strict/ state threads, as
12 -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton
13 -- Jones /Lazy Functional State Threads/.
15 -----------------------------------------------------------------------------
17 module Control.Monad.ST
20 ST, -- abstract, instance of Functor, Monad, Typeable.
21 runST, -- :: (forall s. ST s a) -> a
22 fixST, -- :: (a -> ST s a) -> ST s a
24 -- * Converting 'ST' to 'IO'
25 RealWorld, -- abstract
26 stToIO, -- :: ST RealWorld a -> IO a
28 -- * Unsafe operations
29 unsafeInterleaveST, -- :: ST s a -> ST s a
30 unsafeIOToST, -- :: IO a -> ST s a
31 unsafeSTToIO -- :: ST s a -> IO a
36 import Control.Monad.Fix
43 import qualified Hugs.LazyST as LazyST
45 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
46 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
48 fixST :: (a -> ST s a) -> ST s a
49 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
51 unsafeInterleaveST :: ST s a -> ST s a
53 LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
56 #ifdef __GLASGOW_HASKELL__
57 import GHC.ST ( ST, runST, fixST, unsafeInterleaveST )
58 import GHC.Base ( RealWorld )
59 import GHC.IOBase ( stToIO, unsafeIOToST, unsafeSTToIO )
62 instance MonadFix (ST s) where