Remove unused imports from base
[ghc-base.git] / Control / Monad / ST.hs
1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Control.Monad.ST
5 -- Copyright   :  (c) The University of Glasgow 2001
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  experimental
10 -- Portability :  non-portable (requires universal quantification for runST)
11 --
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/.
15 --
16 -----------------------------------------------------------------------------
17
18 module Control.Monad.ST
19   (
20         -- * The 'ST' Monad
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
24
25         -- * Converting 'ST' to 'IO'
26         RealWorld,              -- abstract
27         stToIO,                 -- :: ST RealWorld a -> IO a
28
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
33       ) where
34
35 import Control.Monad.Fix
36
37 #include "Typeable.h"
38
39 #ifdef __HUGS__
40 import Data.Typeable
41 import Hugs.ST
42 import qualified Hugs.LazyST as LazyST
43
44 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
45 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
46
47 fixST :: (a -> ST s a) -> ST s a
48 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
49
50 unsafeInterleaveST :: ST s a -> ST s a
51 unsafeInterleaveST =
52     LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
53 #endif
54
55 #ifdef __GLASGOW_HASKELL__
56 import GHC.ST           ( ST, runST, fixST, unsafeInterleaveST )
57 import GHC.Base         ( RealWorld )
58 import GHC.IO           ( stToIO, unsafeIOToST, unsafeSTToIO )
59 #endif
60
61 instance MonadFix (ST s) where
62         mfix = fixST
63