1 -----------------------------------------------------------------------------
3 -- Module : Control.Monad.ST
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable
11 -- $Id: ST.hs,v 1.1 2001/06/28 14:15:02 simonmar Exp $
13 -- The State Transformer Monad, ST
15 -----------------------------------------------------------------------------
17 module Control.Monad.ST
19 ST -- abstract, instance of Functor, Monad, Typeable.
20 , runST -- :: (forall s. ST s a) -> a
21 , fixST -- :: (a -> ST s a) -> ST s a
22 , unsafeInterleaveST -- :: ST s a -> ST s a
24 , unsafeIOToST -- :: IO a -> ST s a
26 , RealWorld -- abstract
27 , stToIO -- :: ST RealWorld a -> IO a
34 #ifdef __GLASGOW_HASKELL__
36 import GHC.Prim ( unsafeCoerce#, RealWorld )
37 import GHC.IOBase ( IO(..), stToIO )
39 unsafeIOToST :: IO a -> ST s a
40 unsafeIOToST (IO io) = ST $ \ s ->
41 case ((unsafeCoerce# io) s) of
42 (# new_s, a #) -> unsafeCoerce# (STret new_s a)
45 -- ---------------------------------------------------------------------------
51 instance (Typeable a, Typeable b) => Typeable (ST a b) where
52 typeOf st = mkAppTy sTTc [typeOf ((undefined :: ST a b -> a) st),
53 typeOf ((undefined :: ST a b -> b) st)]