1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 -----------------------------------------------------------------------------
4 -- Module : Control.Monad.ST
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : non-portable (requires universal quantification for runST)
12 -- This library provides support for /strict/ state threads, as
13 -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton
14 -- Jones /Lazy Functional State Threads/.
16 -----------------------------------------------------------------------------
18 module Control.Monad.ST
21 ST, -- abstract, instance of Functor, Monad, Typeable.
22 runST, -- :: (forall s. ST s a) -> a
23 fixST, -- :: (a -> ST s a) -> ST s a
25 -- * Converting 'ST' to 'IO'
26 RealWorld, -- abstract
27 stToIO, -- :: ST RealWorld a -> IO a
29 -- * Unsafe operations
30 unsafeInterleaveST, -- :: ST s a -> ST s a
31 unsafeIOToST, -- :: IO a -> ST s a
32 unsafeSTToIO -- :: ST s a -> IO a
37 import Control.Monad.Fix
44 import qualified Hugs.LazyST as LazyST
46 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
47 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
49 fixST :: (a -> ST s a) -> ST s a
50 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
52 unsafeInterleaveST :: ST s a -> ST s a
54 LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
57 #ifdef __GLASGOW_HASKELL__
58 import GHC.ST ( ST, runST, fixST, unsafeInterleaveST )
59 import GHC.Base ( RealWorld )
60 import GHC.IO ( stToIO, unsafeIOToST, unsafeSTToIO )
63 instance MonadFix (ST s) where