Use explicit language extensions & remove extension fields from base.cabal
[ghc-base.git] / Control / Monad / ST.hs
1 {-# LANGUAGE CPP #-}
2
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module      :  Control.Monad.ST
6 -- Copyright   :  (c) The University of Glasgow 2001
7 -- License     :  BSD-style (see the file libraries/base/LICENSE)
8 -- 
9 -- Maintainer  :  libraries@haskell.org
10 -- Stability   :  experimental
11 -- Portability :  non-portable (requires universal quantification for runST)
12 --
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/.
16 --
17 -----------------------------------------------------------------------------
18
19 module Control.Monad.ST
20   (
21         -- * The 'ST' Monad
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
25
26         -- * Converting 'ST' to 'IO'
27         RealWorld,              -- abstract
28         stToIO,                 -- :: ST RealWorld a -> IO a
29
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
34       ) where
35
36 #if defined(__GLASGOW_HASKELL__)
37 import Control.Monad.Fix ()
38 #else
39 import Control.Monad.Fix
40 #endif
41
42 #include "Typeable.h"
43
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__)
49 import Data.Typeable
50 import Hugs.ST
51 import qualified Hugs.LazyST as LazyST
52 #endif
53
54 #if defined(__HUGS__)
55 INSTANCE_TYPEABLE2(ST,sTTc,"ST")
56 INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
57
58 fixST :: (a -> ST s a) -> ST s a
59 fixST f = LazyST.lazyToStrictST (LazyST.fixST (LazyST.strictToLazyST . f))
60
61 unsafeInterleaveST :: ST s a -> ST s a
62 unsafeInterleaveST =
63     LazyST.lazyToStrictST . LazyST.unsafeInterleaveST . LazyST.strictToLazyST
64 #endif
65
66 #if !defined(__GLASGOW_HASKELL__)
67 instance MonadFix (ST s) where
68         mfix = fixST
69 #endif
70