SafeHaskell: Added SafeHaskell to base
[ghc.git] / libraries / base / Control / Monad / ST / Imp.hs
1 {-# LANGUAGE CPP #-}
2 {-# OPTIONS_HADDOCK hide #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Control.Monad.ST.Imp
7 -- Copyright : (c) The University of Glasgow 2001
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : libraries@haskell.org
11 -- Stability : experimental
12 -- Portability : non-portable (requires universal quantification for runST)
13 --
14 -- This library provides support for /strict/ state threads, as
15 -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton
16 -- Jones /Lazy Functional State Threads/.
17 --
18 -----------------------------------------------------------------------------
19
20 -- #hide
21 module Control.Monad.ST.Imp (
22 -- * The 'ST' Monad
23 ST, -- abstract, instance of Functor, Monad, Typeable.
24 runST, -- :: (forall s. ST s a) -> a
25 fixST, -- :: (a -> ST s a) -> ST s a
26
27 -- * Converting 'ST' to 'IO'
28 RealWorld, -- abstract
29 stToIO, -- :: ST RealWorld a -> IO a
30
31 -- * Unsafe operations
32 unsafeInterleaveST, -- :: ST s a -> ST s a
33 unsafeIOToST, -- :: IO a -> ST s a
34 unsafeSTToIO -- :: ST s a -> IO a
35 ) where
36
37 #if defined(__GLASGOW_HASKELL__)
38 import Control.Monad.Fix ()
39 #else
40 import Control.Monad.Fix
41 #endif
42
43 #include "Typeable.h"
44
45 #if defined(__GLASGOW_HASKELL__)
46 import GHC.ST ( ST, runST, fixST, unsafeInterleaveST )
47 import GHC.Base ( RealWorld )
48 import GHC.IO ( stToIO, unsafeIOToST, unsafeSTToIO )
49 #elif defined(__HUGS__)
50 import Data.Typeable
51 import Hugs.ST
52 import qualified Hugs.LazyST as LazyST
53 #endif
54
55 #if defined(__HUGS__)
56 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
57 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
58
59 fixST :: (a -> ST s a) -> ST s a
60 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
61
62 unsafeInterleaveST :: ST s a -> ST s a
63 unsafeInterleaveST =
64 LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
65 #endif
66
67 #if !defined(__GLASGOW_HASKELL__)
68 instance MonadFix (ST s) where
69 mfix = fixST
70 #endif
71
72