3 -----------------------------------------------------------------------------
5 -- Module : Control.Monad.ST
6 -- Copyright : (c) The University of Glasgow 2001
7 -- License : BSD-style (see the file libraries/base/LICENSE)
9 -- Maintainer : libraries@haskell.org
10 -- Stability : experimental
11 -- Portability : non-portable (requires universal quantification for runST)
13 -- This library provides support for /strict/ state threads, as
14 -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton
15 -- Jones /Lazy Functional State Threads/.
17 -----------------------------------------------------------------------------
19 module Control.Monad.ST
22 ST, -- abstract, instance of Functor, Monad, Typeable.
23 runST, -- :: (forall s. ST s a) -> a
24 fixST, -- :: (a -> ST s a) -> ST s a
26 -- * Converting 'ST' to 'IO'
27 RealWorld, -- abstract
28 stToIO, -- :: ST RealWorld a -> IO a
30 -- * Unsafe operations
31 unsafeInterleaveST, -- :: ST s a -> ST s a
32 unsafeIOToST, -- :: IO a -> ST s a
33 unsafeSTToIO -- :: ST s a -> IO a
36 #if defined(__GLASGOW_HASKELL__)
37 import Control.Monad.Fix ()
39 import Control.Monad.Fix
44 #if defined(__GLASGOW_HASKELL__)
45 import GHC.ST ( ST, runST, fixST, unsafeInterleaveST )
46 import GHC.Base ( RealWorld )
47 import GHC.IO ( stToIO, unsafeIOToST, unsafeSTToIO )
48 #elif defined(__HUGS__)
51 import qualified Hugs.LazyST as LazyST
55 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
56 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
58 fixST :: (a -> ST s a) -> ST s a
59 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
61 unsafeInterleaveST :: ST s a -> ST s a
63 LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
66 #if !defined(__GLASGOW_HASKELL__)
67 instance MonadFix (ST s) where