<commit_before>-----------------------------------------------------------------------------
-- 
-- Module      :  Control.Monad.ST
-- Copyright   :  (c) The University of Glasgow 2001
-- License     :  BSD-style (see the file libraries/core/LICENSE)
-- 
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  non-portable (requires universal quantification for runST)
--
-- $Id: ST.hs,v 1.3 2001/07/03 11:37:49 simonmar Exp $
--
-- The State Transformer Monad, ST
--
-----------------------------------------------------------------------------

module Control.Monad.ST
      (
	ST                  -- abstract, instance of Functor, Monad, Typeable.
      , runST		    -- :: (forall s. ST s a) -> a
      , fixST		    -- :: (a -> ST s a) -> ST s a
      , unsafeInterleaveST  -- :: ST s a -> ST s a

      , unsafeIOToST	    -- :: IO a -> ST s a

      , RealWorld	    -- abstract
      , stToIO		    -- :: ST RealWorld a -> IO a
      ) where

import Prelude

import Control.Monad.Fix
import Data.Dynamic

#ifdef __GLASGOW_HASKELL__
import GHC.ST
import GHC.Prim		( unsafeCoerce#, RealWorld )
import GHC.IOBase 	( IO(..), stToIO )

unsafeIOToST        :: IO a -> ST s a
unsafeIOToST (IO io) = ST $ \ s -> (unsafeCoerce# io) s
#endif

instance MonadFix (ST s) where
	mfix = fixST

-- ---------------------------------------------------------------------------
-- Typeable instance

sTTc :: TyCon
sTTc = mkTyCon "ST"

instance (Typeable a, Typeable b) => Typeable (ST a b) where
  typeOf st = mkAppTy sTTc [typeOf ((undefined :: ST a b -> a) st),
			    typeOf ((undefined :: ST a b -> b) st)]<commit_msg>[project @ 2001-07-31 13:31:44 by simonmar] merge hslibs/lang/ST.lhs rev. 1.14<commit_after>-----------------------------------------------------------------------------
-- 
-- Module      :  Control.Monad.ST
-- Copyright   :  (c) The University of Glasgow 2001
-- License     :  BSD-style (see the file libraries/core/LICENSE)
-- 
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  non-portable (requires universal quantification for runST)
--
-- $Id: ST.hs,v 1.4 2001/07/31 13:31:44 simonmar Exp $
--
-- The State Transformer Monad, ST
--
-----------------------------------------------------------------------------

module Control.Monad.ST
      (
	ST                  -- abstract, instance of Functor, Monad, Typeable.
      , runST		    -- :: (forall s. ST s a) -> a
      , fixST		    -- :: (a -> ST s a) -> ST s a
      , unsafeInterleaveST  -- :: ST s a -> ST s a

      , unsafeIOToST	    -- :: IO a -> ST s a

      , RealWorld	    -- abstract
      , stToIO		    -- :: ST RealWorld a -> IO a
      ) where

import Prelude

import Control.Monad.Fix
import Data.Dynamic

#ifdef __GLASGOW_HASKELL__
import GHC.ST
import GHC.Prim		( 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 -> (unsafeCoerce# io) s
#endif

instance MonadFix (ST s) where
	mfix = fixST

-- ---------------------------------------------------------------------------
-- Typeable instance

sTTc :: TyCon
sTTc = mkTyCon "ST"

instance (Typeable a, Typeable b) => Typeable (ST a b) where
  typeOf st = mkAppTy sTTc [typeOf ((undefined :: ST a b -> a) st),
			    typeOf ((undefined :: ST a b -> b) st)]
{'fraction_non_alphanumeric': 0.24803034724248613, 'fraction_numerical': 0.0166326232856726, 'mean_word_length': 1.4538296349319972, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6182056', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1054, 'n_words': 346}