-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A monad transformer version of the ST monad
--   
--   A monad transformer version of the ST monad Warning! This monad
--   transformer should not be used with monads that can contain multiple
--   answers, like the list monad. The reason is that the state token will
--   be duplicated across the different answers and this causes Bad Things
--   to happen (such as loss of referential transparency). Safe monads
--   include the monads State, Reader, Writer, Maybe and combinations of
--   their corresponding monad transformers.
@package STMonadTrans
@version 0.3.4


-- | This module provides the implementation of the <a>STT</a> type for
--   those occasions where it's needed in order to implement new liftings
--   through operations in other monads.
--   
--   Warning! This monad transformer should not be used with monads that
--   can contain multiple answers, like the list monad. The reason is that
--   the will be duplicated across the different answers and this cause Bad
--   Things to happen (such as loss of referential transparency). Safe
--   monads include the monads State, Reader, Writer, Maybe and
--   combinations of their corresponding monad transformers.
module Control.Monad.ST.Trans.Internal

-- | <a>STT</a> is the monad transformer providing polymorphic updateable
--   references
newtype STT s m a
STT :: (State# s -> m (STTRet s a)) -> STT s m a
unSTT :: STT s m a -> (State# s -> m (STTRet s a))

-- | <a>STTRet</a> is needed to encapsulate the unboxed state token that
--   GHC passes around. This type is essentially a pair, but an ordinary
--   pair is not not allowed to contain unboxed types.
data STTRet s a
STTRet :: (State# s) -> a -> STTRet s a


-- | This library provides a monad transformer version of the ST monad.
--   
--   Warning! This monad transformer should not be used with monads that
--   can contain multiple answers, like the list monad. The reason is that
--   the will be duplicated across the different answers and this cause Bad
--   Things to happen (such as loss of referential transparency). Safe
--   monads include the monads State, Reader, Writer, Maybe and
--   combinations of their corresponding monad transformers.
module Control.Monad.ST.Trans

-- | <a>STT</a> is the monad transformer providing polymorphic updateable
--   references
data STT s m a

-- | Executes a computation in the <a>STT</a> monad transformer
runST :: Monad m => (forall s. STT s m a) -> m a

-- | Mutable references
data STRef s a

-- | Create a new reference
newSTRef :: Monad m => a -> STT s m (STRef s a)

-- | Reads the value of a reference
readSTRef :: Monad m => STRef s a -> STT s m a

-- | Modifies the value of a reference
writeSTRef :: Monad m => STRef s a -> a -> STT s m ()

-- | Mutable arrays
data STArray s i e

-- | Creates a new mutable array
newSTArray :: (Ix i, Monad m) => (i, i) -> e -> STT s m (STArray s i e)

-- | Retrieves an element from the array
readSTArray :: (Ix i, Monad m) => STArray s i e -> i -> STT s m e

-- | Modifies an element in the array
writeSTArray :: (Ix i, Monad m) => STArray s i e -> i -> e -> STT s m ()

-- | Returns the lowest and highest indices of the array
boundsSTArray :: STArray s i e -> (i, i)

-- | Returns the number of elements in the array
numElementsSTArray :: STArray s i e -> Int

-- | Copy a mutable array and turn it into an immutable array
freezeSTArray :: (Ix i, Monad m) => STArray s i e -> STT s m (Array i e)

-- | Copy an immutable array and turn it into a mutable array
thawSTArray :: (Ix i, Monad m) => Array i e -> STT s m (STArray s i e)

-- | A safe way to create and work with a mutable array before returning an
--   immutable array for later perusal. This function avoids copying the
--   array before returning it.
runSTArray :: (Ix i, Monad m) => (forall s. STT s m (STArray s i e)) -> m (Array i e)
unsafeIOToSTT :: (Monad m) => IO a -> STT s m a
unsafeSTToIO :: STT s IO a -> IO a
unsafeSTRefToIORef :: STRef s a -> IORef a
unsafeIORefToSTRef :: IORef a -> STRef s a
instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.ST.Trans.Internal.STT s m)
instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.ST.Trans.Internal.STT s)
instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Control.Monad.ST.Trans.Internal.STT s m)
instance GHC.Base.Functor (Control.Monad.ST.Trans.Internal.STTRet s)
instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Monad m, GHC.Base.Functor m) => GHC.Base.Applicative (Control.Monad.ST.Trans.Internal.STT s m)
instance GHC.Classes.Eq (Control.Monad.ST.Trans.STRef s a)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.ST.Trans.Internal.STT s m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.ST.Trans.Internal.STT s m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.ST.Trans.Internal.STT s' m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.ST.Trans.Internal.STT s m)
instance GHC.Classes.Eq (Control.Monad.ST.Trans.STArray s i e)
