-----------------------------------------------------------------------------
---
+-- |
-- Module : Control.Monad.ST
-- Copyright : (c) The University of Glasgow 2001
--- License : BSD-style (see the file libraries/core/LICENSE)
+-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
--- Portability : non-portable
---
--- $Id: ST.hs,v 1.1 2001/06/28 14:15:02 simonmar Exp $
+-- Portability : non-portable (requires universal quantification for runST)
--
-- The State Transformer Monad, ST
--
import Prelude
+import Control.Monad.Fix
import Data.Dynamic
#ifdef __GLASGOW_HASKELL__
import GHC.ST
-import GHC.Prim ( unsafeCoerce#, RealWorld )
+import GHC.Base ( unsafeCoerce#, RealWorld )
import GHC.IOBase ( IO(..), stToIO )
+-- This relies on IO and ST having the same representation modulo the
+-- constraint on the type of the state
+--
unsafeIOToST :: IO a -> ST s a
-unsafeIOToST (IO io) = ST $ \ s ->
- case ((unsafeCoerce# io) s) of
- (# new_s, a #) -> unsafeCoerce# (STret new_s a)
+unsafeIOToST (IO io) = ST $ \ s -> (unsafeCoerce# io) s
#endif
+instance MonadFix (ST s) where
+ mfix = fixST
+
-- ---------------------------------------------------------------------------
-- Typeable instance