-- 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.4.3


-- | 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

-- | Lifting the <a>ST</a> monad into <a>STT</a>. The library uses this
--   function extensively to be able to reuse functions from <a>ST</a>.
liftST :: Applicative m => ST s a -> STT s m a
liftSTT :: STT s m a -> State# s -> m (STTRet 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 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.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (GHC.Arr.STArray s) e (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Bool (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Char (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Int (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Word (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) (GHC.Ptr.Ptr a) (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) (GHC.Ptr.FunPtr a) (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Float (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Types.Double (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) (GHC.Stable.StablePtr a) (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Int.Int8 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Int.Int16 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Int.Int32 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Int.Int64 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Word.Word8 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Word.Word16 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Word.Word32 (Control.Monad.ST.Trans.Internal.STT s m)
instance (GHC.Base.Applicative m, GHC.Base.Monad m) => Data.Array.Base.MArray (Data.Array.Base.STUArray s) GHC.Word.Word64 (Control.Monad.ST.Trans.Internal.STT s m)


-- | 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 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.
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

-- | <i>Deprecated: Use runSTT instead</i>
runST :: Monad m => (forall s. STT s m a) -> m a

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

-- | a value of type <tt>STRef s a</tt> is a mutable variable in state
--   thread <tt>s</tt>, containing a value of type <tt>a</tt>
data STRef s a :: * -> * -> *

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

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

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

-- | Mutable, boxed, non-strict arrays in the <a>ST</a> monad. The type
--   arguments are as follows:
--   
--   <ul>
--   <li><tt>s</tt>: the state variable argument for the <a>ST</a>
--   type</li>
--   <li><tt>i</tt>: the index type of the array (should be an instance of
--   <a>Ix</a>)</li>
--   <li><tt>e</tt>: the element type of the array.</li>
--   </ul>
data STArray s i e :: * -> * -> * -> *

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

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

-- | Modifies an element in the array
writeSTArray :: (Ix i, Applicative m, 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, Applicative m, 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, Applicative m, 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, Applicative m, Monad m) => (forall s. STT s m (STArray s i e)) -> m (Array i e)
unsafeReadSTArray :: (Ix i, Applicative m, Monad m) => STArray s i e -> Int -> STT s m e
unsafeWriteSTArray :: (Ix i, Applicative m, Monad m) => STArray s i e -> Int -> e -> STT s m ()
unsafeFreezeSTArray :: (Ix i, Applicative m, Monad m) => STArray s i e -> STT s m (Array i e)
unsafeThawSTArray :: (Ix i, Applicative m, Monad m) => Array i e -> STT s m (STArray s i e)
unsafeIOToSTT :: (Monad m) => IO a -> STT s m a

-- | <i>Deprecated: Use unsafeSTTToIO instead</i>
unsafeSTToIO :: STT s IO a -> IO a
unsafeSTTToIO :: STT s IO a -> IO a
unsafeSTRefToIORef :: STRef s a -> IORef a
unsafeIORefToSTRef :: IORef a -> STRef s a
