    {-# LANGUAGE MagicHash, UnboxedTuples, Rank2Types, FlexibleInstances,
        MultiParamTypeClasses, UndecidableInstances, RecursiveDo #-}
    {- |
       Module      :  Control.Monad.ST.Trans
       Copyright   :  Josef Svenningsson 2008-2010
                      (c) The University of Glasgow, 1994-2000
       License     :  BSD

       Maintainer  :  josef.svenningsson@gmail.com
       Stability   :  experimental
       Portability :  non-portable (GHC Extensions)

       This module provides the implementation of the 'STT' 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 where

    import GHC.Base
    import GHC.ST hiding (liftST)

    import qualified Control.Monad.Fail as MF
    import Control.Monad.Fix
    import Control.Monad.Trans
    import Control.Monad.Error.Class
    import Control.Monad.Reader.Class
    import Control.Monad.State.Class
    import Control.Monad.Writer.Class

    #if __GLASGOW_HASKELL__ <= 708
    import Control.Applicative
    #endif

    import Data.Array.ST
    import Data.Array.Base
    import GHC.Int    (      Int8,  Int16,  Int32,  Int64)
    import GHC.Word   (Word, Word8, Word16, Word32, Word64)
    import GHC.Ptr    (Ptr, FunPtr)
    import GHC.Stable (StablePtr)

    -- | 'STT' is the monad transformer providing polymorphic updateable references
    newtype STT s m a = STT (State# s -> m (STTRet s a))

    unSTT :: STT s m a -> (State# s -> m (STTRet s a))
    unSTT :: STT s m a -> State# s -> m (STTRet s a)
    unSTT (STT f :: State# s -> m (STTRet s a)
    f) = State# s -> m (STTRet s a)
    f

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

    -- | Lifting the `ST` monad into `STT`. The library uses this function
    --   extensively to be able to reuse functions from `ST`.
    liftST :: Applicative m => ST s a -> STT s m a
    liftST :: ST s a -> STT s m a
    liftST (ST f :: STRep s a
    f) = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT (\s :: State# s
    s -> let (# s' :: State# s
    s', a :: a
    a #) = STRep s a
    f State# s
    s in STTRet s a -> m (STTRet s a)
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (State# s -> a -> STTRet s a
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    s' a
    a))
    {-# INLINE liftST #-}

    -- All instances have to go in this module because otherwise they
    -- would be orphan instances.

    instance Monad m => Monad (STT s m) where
      return :: a -> STT s m a
    return a :: a
    a = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \st :: State# s
    st -> STTRet s a -> m (STTRet s a)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> a -> STTRet s a
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    st a
    a)
      STT m :: State# s -> m (STTRet s a)
    m >>= :: STT s m a -> (a -> STT s m b) -> STT s m b
    >>= k :: a -> STT s m b
    k = (State# s -> m (STTRet s b)) -> STT s m b
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s b)) -> STT s m b)
    -> (State# s -> m (STTRet s b)) -> STT s m b
    forall a b. (a -> b) -> a -> b
    $ \st :: State# s
    st ->
        do STTRet s a
    ret <- State# s -> m (STTRet s a)
    m State# s
    st
           case STTRet s a
    ret of
             STTRet new_st :: State# s
    new_st a :: a
    a ->
                 STT s m b -> State# s -> m (STTRet s b)
    forall s (m :: * -> *) a. STT s m a -> State# s -> m (STTRet s a)
    unSTT (a -> STT s m b
    k a
    a) State# s
    new_st

    instance MF.MonadFail m => MF.MonadFail (STT s m) where
      fail :: String -> STT s m a
    fail msg :: String
    msg = m a -> STT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (String -> m a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail String
    msg)

    instance MonadTrans (STT s) where
      lift :: m a -> STT s m a
    lift m :: m a
    m = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \st :: State# s
    st ->
       do a
    a <- m a
    m
          STTRet s a -> m (STTRet s a)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> a -> STTRet s a
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    st a
    a)

    liftSTT :: STT s m a -> State# s -> m (STTRet s a)
    liftSTT :: STT s m a -> State# s -> m (STTRet s a)
    liftSTT (STT m :: State# s -> m (STTRet s a)
    m) s :: State# s
    s = State# s -> m (STTRet s a)
    m State# s
    s

    instance (MonadFix m) => MonadFix (STT s m) where
      mfix :: (a -> STT s m a) -> STT s m a
    mfix k :: a -> STT s m a
    k = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \ s :: State# s
    s -> mdo
        ans :: STTRet s a
    ans@(STTRet _ r :: a
    r) <- STT s m a -> State# s -> m (STTRet s a)
    forall s (m :: * -> *) a. STT s m a -> State# s -> m (STTRet s a)
    liftSTT (a -> STT s m a
    k a
    r) State# s
    s
        STTRet s a -> m (STTRet s a)
    forall (m :: * -> *) a. Monad m => a -> m a
    return STTRet s a
    ans

    instance Functor (STTRet s) where
      fmap :: (a -> b) -> STTRet s a -> STTRet s b
    fmap f :: a -> b
    f (STTRet s :: State# s
    s a :: a
    a) = State# s -> b -> STTRet s b
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    s (a -> b
    f a
    a)

    instance Functor m => Functor (STT s m) where
      fmap :: (a -> b) -> STT s m a -> STT s m b
    fmap f :: a -> b
    f (STT g :: State# s -> m (STTRet s a)
    g) = (State# s -> m (STTRet s b)) -> STT s m b
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s b)) -> STT s m b)
    -> (State# s -> m (STTRet s b)) -> STT s m b
    forall a b. (a -> b) -> a -> b
    $ \s# :: State# s
    s# -> ((STTRet s a -> STTRet s b) -> m (STTRet s a) -> m (STTRet s b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((STTRet s a -> STTRet s b) -> m (STTRet s a) -> m (STTRet s b))
    -> ((a -> b) -> STTRet s a -> STTRet s b)
    -> (a -> b)
    -> m (STTRet s a)
    -> m (STTRet s b)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> b) -> STTRet s a -> STTRet s b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap) a -> b
    f (State# s -> m (STTRet s a)
    g State# s
    s#)

    instance (Monad m, Functor m) => Applicative (STT s m) where
      pure :: a -> STT s m a
    pure a :: a
    a = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \s# :: State# s
    s# -> STTRet s a -> m (STTRet s a)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> a -> STTRet s a
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    s# a
    a)
      (STT m :: State# s -> m (STTRet s (a -> b))
    m) <*> :: STT s m (a -> b) -> STT s m a -> STT s m b
    <*> (STT n :: State# s -> m (STTRet s a)
    n) = (State# s -> m (STTRet s b)) -> STT s m b
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s b)) -> STT s m b)
    -> (State# s -> m (STTRet s b)) -> STT s m b
    forall a b. (a -> b) -> a -> b
    $ \s1 :: State# s
    s1 ->
                            do (STTRet s2 :: State# s
    s2 f :: a -> b
    f) <- State# s -> m (STTRet s (a -> b))
    m State# s
    s1
                               (STTRet s3 :: State# s
    s3 x :: a
    x) <- State# s -> m (STTRet s a)
    n State# s
    s2
                               STTRet s b -> m (STTRet s b)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> b -> STTRet s b
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    s3 (a -> b
    f a
    x))

    -- Instances of other monad classes

    instance MonadError e m => MonadError e (STT s m) where
      throwError :: e -> STT s m a
    throwError e :: e
    e = m a -> STT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (e -> m a
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError e
    e)
      catchError :: STT s m a -> (e -> STT s m a) -> STT s m a
    catchError (STT m :: State# s -> m (STTRet s a)
    m) f :: e -> STT s m a
    f = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \st :: State# s
    st -> m (STTRet s a) -> (e -> m (STTRet s a)) -> m (STTRet s a)
    forall e (m :: * -> *) a.
    MonadError e m =>
    m a -> (e -> m a) -> m a
    catchError (State# s -> m (STTRet s a)
    m State# s
    st)
                             (\e :: e
    e -> STT s m a -> State# s -> m (STTRet s a)
    forall s (m :: * -> *) a. STT s m a -> State# s -> m (STTRet s a)
    unSTT (e -> STT s m a
    f e
    e) State# s
    st)

    instance MonadReader r m => MonadReader r (STT s m) where
      ask :: STT s m r
    ask = m r -> STT s m r
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift m r
    forall r (m :: * -> *). MonadReader r m => m r
    ask
      local :: (r -> r) -> STT s m a -> STT s m a
    local f :: r -> r
    f (STT m :: State# s -> m (STTRet s a)
    m) = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \st :: State# s
    st -> (r -> r) -> m (STTRet s a) -> m (STTRet s a)
    forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
    local r -> r
    f (State# s -> m (STTRet s a)
    m State# s
    st)

    instance MonadState s m => MonadState s (STT s' m) where
      get :: STT s' m s
    get = m s -> STT s' m s
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift m s
    forall s (m :: * -> *). MonadState s m => m s
    get
      put :: s -> STT s' m ()
    put s :: s
    s = m () -> STT s' m ()
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (s -> m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put s
    s)

    instance MonadWriter w m => MonadWriter w (STT s m) where
      tell :: w -> STT s m ()
    tell w :: w
    w = m () -> STT s m ()
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (w -> m ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell w
    w)
      listen :: STT s m a -> STT s m (a, w)
    listen (STT m :: State# s -> m (STTRet s a)
    m)= (State# s -> m (STTRet s (a, w))) -> STT s m (a, w)
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s (a, w))) -> STT s m (a, w))
    -> (State# s -> m (STTRet s (a, w))) -> STT s m (a, w)
    forall a b. (a -> b) -> a -> b
    $ \st1 :: State# s
    st1 -> do (STTRet st2 :: State# s
    st2 a :: a
    a, w :: w
    w) <- m (STTRet s a) -> m (STTRet s a, w)
    forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
    listen (State# s -> m (STTRet s a)
    m State# s
    st1)
                                       STTRet s (a, w) -> m (STTRet s (a, w))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> (a, w) -> STTRet s (a, w)
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    st2 (a
    a,w
    w))
      pass :: STT s m (a, w -> w) -> STT s m a
    pass (STT m :: State# s -> m (STTRet s (a, w -> w))
    m) = (State# s -> m (STTRet s a)) -> STT s m a
    forall s (m :: * -> *) a. (State# s -> m (STTRet s a)) -> STT s m a
    STT ((State# s -> m (STTRet s a)) -> STT s m a)
    -> (State# s -> m (STTRet s a)) -> STT s m a
    forall a b. (a -> b) -> a -> b
    $ \st1 :: State# s
    st1 -> m (STTRet s a, w -> w) -> m (STTRet s a)
    forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
    pass (do (STTRet st2 :: State# s
    st2 (a :: a
    a,f :: w -> w
    f)) <- State# s -> m (STTRet s (a, w -> w))
    m State# s
    st1
                                            (STTRet s a, w -> w) -> m (STTRet s a, w -> w)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (State# s -> a -> STTRet s a
    forall s a. State# s -> a -> STTRet s a
    STTRet State# s
    st2 a
    a, w -> w
    f))

    -- MArray instances

    instance (Applicative m, Monad m) => MArray (STArray s) e (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STArray s i e -> STT s m (i, i)
    getBounds arr :: STArray s i e
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STArray s i e -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STArray s i e
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STArray s i e -> STT s m Int
    getNumElements arr :: STArray s i e
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STArray s i e -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STArray s i e
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> e -> STT s m (STArray s i e)
    newArray bnds :: (i, i)
    bnds e :: e
    e = ST s (STArray s i e) -> STT s m (STArray s i e)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> e -> ST s (STArray s i e)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds e
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STArray s i e -> Int -> STT s m e
    unsafeRead arr :: STArray s i e
    arr i :: Int
    i = ST s e -> STT s m e
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STArray s i e -> Int -> ST s e
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STArray s i e
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STArray s i e -> Int -> e -> STT s m ()
    unsafeWrite arr :: STArray s i e
    arr i :: Int
    i e :: e
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STArray s i e -> Int -> e -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STArray s i e
    arr Int
    i e
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Bool (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Bool -> STT s m (i, i)
    getBounds arr :: STUArray s i Bool
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Bool -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Bool
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Bool -> STT s m Int
    getNumElements arr :: STUArray s i Bool
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Bool -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Bool
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Bool -> STT s m (STUArray s i Bool)
    newArray bnds :: (i, i)
    bnds e :: Bool
    e = ST s (STUArray s i Bool) -> STT s m (STUArray s i Bool)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Bool -> ST s (STUArray s i Bool)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Bool
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Bool -> Int -> STT s m Bool
    unsafeRead arr :: STUArray s i Bool
    arr i :: Int
    i = ST s Bool -> STT s m Bool
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Bool -> Int -> ST s Bool
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Bool
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Bool -> Int -> Bool -> STT s m ()
    unsafeWrite arr :: STUArray s i Bool
    arr i :: Int
    i e :: Bool
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Bool -> Int -> Bool -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Bool
    arr Int
    i Bool
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Char (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Char -> STT s m (i, i)
    getBounds arr :: STUArray s i Char
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Char -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Char
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Char -> STT s m Int
    getNumElements arr :: STUArray s i Char
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Char -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Char
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Char -> STT s m (STUArray s i Char)
    newArray bnds :: (i, i)
    bnds e :: Char
    e = ST s (STUArray s i Char) -> STT s m (STUArray s i Char)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Char -> ST s (STUArray s i Char)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Char
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Char -> Int -> STT s m Char
    unsafeRead arr :: STUArray s i Char
    arr i :: Int
    i = ST s Char -> STT s m Char
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Char -> Int -> ST s Char
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Char
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Char -> Int -> Char -> STT s m ()
    unsafeWrite arr :: STUArray s i Char
    arr i :: Int
    i e :: Char
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Char -> Int -> Char -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Char
    arr Int
    i Char
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Int (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Int -> STT s m (i, i)
    getBounds arr :: STUArray s i Int
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Int
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Int -> STT s m Int
    getNumElements arr :: STUArray s i Int
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Int
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Int -> STT s m (STUArray s i Int)
    newArray bnds :: (i, i)
    bnds e :: Int
    e = ST s (STUArray s i Int) -> STT s m (STUArray s i Int)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Int -> ST s (STUArray s i Int)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Int
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Int -> Int -> STT s m Int
    unsafeRead arr :: STUArray s i Int
    arr i :: Int
    i = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int -> Int -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Int
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Int -> Int -> Int -> STT s m ()
    unsafeWrite arr :: STUArray s i Int
    arr i :: Int
    i e :: Int
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int -> Int -> Int -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Int
    arr Int
    i Int
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Word (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Word -> STT s m (i, i)
    getBounds arr :: STUArray s i Word
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Word
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Word -> STT s m Int
    getNumElements arr :: STUArray s i Word
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Word
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Word -> STT s m (STUArray s i Word)
    newArray bnds :: (i, i)
    bnds e :: Word
    e = ST s (STUArray s i Word) -> STT s m (STUArray s i Word)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Word -> ST s (STUArray s i Word)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Word
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Word -> Int -> STT s m Word
    unsafeRead arr :: STUArray s i Word
    arr i :: Int
    i = ST s Word -> STT s m Word
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word -> Int -> ST s Word
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Word
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Word -> Int -> Word -> STT s m ()
    unsafeWrite arr :: STUArray s i Word
    arr i :: Int
    i e :: Word
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word -> Int -> Word -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Word
    arr Int
    i Word
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) (Ptr a) (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i (Ptr a) -> STT s m (i, i)
    getBounds arr :: STUArray s i (Ptr a)
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (Ptr a) -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i (Ptr a)
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i (Ptr a) -> STT s m Int
    getNumElements arr :: STUArray s i (Ptr a)
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (Ptr a) -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i (Ptr a)
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Ptr a -> STT s m (STUArray s i (Ptr a))
    newArray bnds :: (i, i)
    bnds e :: Ptr a
    e = ST s (STUArray s i (Ptr a)) -> STT s m (STUArray s i (Ptr a))
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Ptr a -> ST s (STUArray s i (Ptr a))
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Ptr a
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i (Ptr a) -> Int -> STT s m (Ptr a)
    unsafeRead arr :: STUArray s i (Ptr a)
    arr i :: Int
    i = ST s (Ptr a) -> STT s m (Ptr a)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (Ptr a) -> Int -> ST s (Ptr a)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i (Ptr a)
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i (Ptr a) -> Int -> Ptr a -> STT s m ()
    unsafeWrite arr :: STUArray s i (Ptr a)
    arr i :: Int
    i e :: Ptr a
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (Ptr a) -> Int -> Ptr a -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i (Ptr a)
    arr Int
    i Ptr a
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) (FunPtr a) (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i (FunPtr a) -> STT s m (i, i)
    getBounds arr :: STUArray s i (FunPtr a)
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (FunPtr a) -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i (FunPtr a)
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i (FunPtr a) -> STT s m Int
    getNumElements arr :: STUArray s i (FunPtr a)
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (FunPtr a) -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i (FunPtr a)
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> FunPtr a -> STT s m (STUArray s i (FunPtr a))
    newArray bnds :: (i, i)
    bnds e :: FunPtr a
    e = ST s (STUArray s i (FunPtr a)) -> STT s m (STUArray s i (FunPtr a))
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> FunPtr a -> ST s (STUArray s i (FunPtr a))
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds FunPtr a
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i (FunPtr a) -> Int -> STT s m (FunPtr a)
    unsafeRead arr :: STUArray s i (FunPtr a)
    arr i :: Int
    i = ST s (FunPtr a) -> STT s m (FunPtr a)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (FunPtr a) -> Int -> ST s (FunPtr a)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i (FunPtr a)
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i (FunPtr a) -> Int -> FunPtr a -> STT s m ()
    unsafeWrite arr :: STUArray s i (FunPtr a)
    arr i :: Int
    i e :: FunPtr a
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (FunPtr a) -> Int -> FunPtr a -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i (FunPtr a)
    arr Int
    i FunPtr a
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Float (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Float -> STT s m (i, i)
    getBounds arr :: STUArray s i Float
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Float -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Float
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Float -> STT s m Int
    getNumElements arr :: STUArray s i Float
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Float -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Float
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Float -> STT s m (STUArray s i Float)
    newArray bnds :: (i, i)
    bnds e :: Float
    e = ST s (STUArray s i Float) -> STT s m (STUArray s i Float)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Float -> ST s (STUArray s i Float)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Float
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Float -> Int -> STT s m Float
    unsafeRead arr :: STUArray s i Float
    arr i :: Int
    i = ST s Float -> STT s m Float
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Float -> Int -> ST s Float
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Float
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Float -> Int -> Float -> STT s m ()
    unsafeWrite arr :: STUArray s i Float
    arr i :: Int
    i e :: Float
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Float -> Int -> Float -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Float
    arr Int
    i Float
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Double (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Double -> STT s m (i, i)
    getBounds arr :: STUArray s i Double
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Double -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Double
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Double -> STT s m Int
    getNumElements arr :: STUArray s i Double
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Double -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Double
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Double -> STT s m (STUArray s i Double)
    newArray bnds :: (i, i)
    bnds e :: Double
    e = ST s (STUArray s i Double) -> STT s m (STUArray s i Double)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Double -> ST s (STUArray s i Double)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Double
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Double -> Int -> STT s m Double
    unsafeRead arr :: STUArray s i Double
    arr i :: Int
    i = ST s Double -> STT s m Double
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Double -> Int -> ST s Double
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Double
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Double -> Int -> Double -> STT s m ()
    unsafeWrite arr :: STUArray s i Double
    arr i :: Int
    i e :: Double
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Double -> Int -> Double -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Double
    arr Int
    i Double
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) (StablePtr a) (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i (StablePtr a) -> STT s m (i, i)
    getBounds arr :: STUArray s i (StablePtr a)
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (StablePtr a) -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i (StablePtr a)
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i (StablePtr a) -> STT s m Int
    getNumElements arr :: STUArray s i (StablePtr a)
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (StablePtr a) -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i (StablePtr a)
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> StablePtr a -> STT s m (STUArray s i (StablePtr a))
    newArray bnds :: (i, i)
    bnds e :: StablePtr a
    e = ST s (STUArray s i (StablePtr a))
    -> STT s m (STUArray s i (StablePtr a))
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> StablePtr a -> ST s (STUArray s i (StablePtr a))
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds StablePtr a
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i (StablePtr a) -> Int -> STT s m (StablePtr a)
    unsafeRead arr :: STUArray s i (StablePtr a)
    arr i :: Int
    i = ST s (StablePtr a) -> STT s m (StablePtr a)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (StablePtr a) -> Int -> ST s (StablePtr a)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i (StablePtr a)
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i (StablePtr a) -> Int -> StablePtr a -> STT s m ()
    unsafeWrite arr :: STUArray s i (StablePtr a)
    arr i :: Int
    i e :: StablePtr a
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i (StablePtr a) -> Int -> StablePtr a -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i (StablePtr a)
    arr Int
    i StablePtr a
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Int8 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Int8 -> STT s m (i, i)
    getBounds arr :: STUArray s i Int8
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int8 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Int8
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Int8 -> STT s m Int
    getNumElements arr :: STUArray s i Int8
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int8 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Int8
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Int8 -> STT s m (STUArray s i Int8)
    newArray bnds :: (i, i)
    bnds e :: Int8
    e = ST s (STUArray s i Int8) -> STT s m (STUArray s i Int8)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Int8 -> ST s (STUArray s i Int8)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Int8
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Int8 -> Int -> STT s m Int8
    unsafeRead arr :: STUArray s i Int8
    arr i :: Int
    i = ST s Int8 -> STT s m Int8
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int8 -> Int -> ST s Int8
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Int8
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Int8 -> Int -> Int8 -> STT s m ()
    unsafeWrite arr :: STUArray s i Int8
    arr i :: Int
    i e :: Int8
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int8 -> Int -> Int8 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Int8
    arr Int
    i Int8
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Int16 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Int16 -> STT s m (i, i)
    getBounds arr :: STUArray s i Int16
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int16 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Int16
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Int16 -> STT s m Int
    getNumElements arr :: STUArray s i Int16
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int16 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Int16
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Int16 -> STT s m (STUArray s i Int16)
    newArray bnds :: (i, i)
    bnds e :: Int16
    e = ST s (STUArray s i Int16) -> STT s m (STUArray s i Int16)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Int16 -> ST s (STUArray s i Int16)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Int16
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Int16 -> Int -> STT s m Int16
    unsafeRead arr :: STUArray s i Int16
    arr i :: Int
    i = ST s Int16 -> STT s m Int16
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int16 -> Int -> ST s Int16
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Int16
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Int16 -> Int -> Int16 -> STT s m ()
    unsafeWrite arr :: STUArray s i Int16
    arr i :: Int
    i e :: Int16
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int16 -> Int -> Int16 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Int16
    arr Int
    i Int16
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Int32 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Int32 -> STT s m (i, i)
    getBounds arr :: STUArray s i Int32
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int32 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Int32
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Int32 -> STT s m Int
    getNumElements arr :: STUArray s i Int32
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int32 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Int32
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Int32 -> STT s m (STUArray s i Int32)
    newArray bnds :: (i, i)
    bnds e :: Int32
    e = ST s (STUArray s i Int32) -> STT s m (STUArray s i Int32)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Int32 -> ST s (STUArray s i Int32)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Int32
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Int32 -> Int -> STT s m Int32
    unsafeRead arr :: STUArray s i Int32
    arr i :: Int
    i = ST s Int32 -> STT s m Int32
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int32 -> Int -> ST s Int32
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Int32
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Int32 -> Int -> Int32 -> STT s m ()
    unsafeWrite arr :: STUArray s i Int32
    arr i :: Int
    i e :: Int32
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int32 -> Int -> Int32 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Int32
    arr Int
    i Int32
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Int64 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Int64 -> STT s m (i, i)
    getBounds arr :: STUArray s i Int64
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int64 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Int64
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Int64 -> STT s m Int
    getNumElements arr :: STUArray s i Int64
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int64 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Int64
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Int64 -> STT s m (STUArray s i Int64)
    newArray bnds :: (i, i)
    bnds e :: Int64
    e = ST s (STUArray s i Int64) -> STT s m (STUArray s i Int64)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Int64 -> ST s (STUArray s i Int64)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Int64
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Int64 -> Int -> STT s m Int64
    unsafeRead arr :: STUArray s i Int64
    arr i :: Int
    i = ST s Int64 -> STT s m Int64
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int64 -> Int -> ST s Int64
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Int64
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Int64 -> Int -> Int64 -> STT s m ()
    unsafeWrite arr :: STUArray s i Int64
    arr i :: Int
    i e :: Int64
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Int64 -> Int -> Int64 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Int64
    arr Int
    i Int64
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Word8 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Word8 -> STT s m (i, i)
    getBounds arr :: STUArray s i Word8
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word8 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Word8
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Word8 -> STT s m Int
    getNumElements arr :: STUArray s i Word8
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word8 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Word8
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Word8 -> STT s m (STUArray s i Word8)
    newArray bnds :: (i, i)
    bnds e :: Word8
    e = ST s (STUArray s i Word8) -> STT s m (STUArray s i Word8)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Word8 -> ST s (STUArray s i Word8)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Word8
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Word8 -> Int -> STT s m Word8
    unsafeRead arr :: STUArray s i Word8
    arr i :: Int
    i = ST s Word8 -> STT s m Word8
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word8 -> Int -> ST s Word8
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Word8
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Word8 -> Int -> Word8 -> STT s m ()
    unsafeWrite arr :: STUArray s i Word8
    arr i :: Int
    i e :: Word8
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word8 -> Int -> Word8 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Word8
    arr Int
    i Word8
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Word16 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Word16 -> STT s m (i, i)
    getBounds arr :: STUArray s i Word16
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word16 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Word16
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Word16 -> STT s m Int
    getNumElements arr :: STUArray s i Word16
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word16 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Word16
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Word16 -> STT s m (STUArray s i Word16)
    newArray bnds :: (i, i)
    bnds e :: Word16
    e = ST s (STUArray s i Word16) -> STT s m (STUArray s i Word16)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Word16 -> ST s (STUArray s i Word16)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Word16
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Word16 -> Int -> STT s m Word16
    unsafeRead arr :: STUArray s i Word16
    arr i :: Int
    i = ST s Word16 -> STT s m Word16
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word16 -> Int -> ST s Word16
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Word16
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Word16 -> Int -> Word16 -> STT s m ()
    unsafeWrite arr :: STUArray s i Word16
    arr i :: Int
    i e :: Word16
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word16 -> Int -> Word16 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Word16
    arr Int
    i Word16
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Word32 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Word32 -> STT s m (i, i)
    getBounds arr :: STUArray s i Word32
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word32 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Word32
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Word32 -> STT s m Int
    getNumElements arr :: STUArray s i Word32
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word32 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Word32
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Word32 -> STT s m (STUArray s i Word32)
    newArray bnds :: (i, i)
    bnds e :: Word32
    e = ST s (STUArray s i Word32) -> STT s m (STUArray s i Word32)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Word32 -> ST s (STUArray s i Word32)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Word32
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Word32 -> Int -> STT s m Word32
    unsafeRead arr :: STUArray s i Word32
    arr i :: Int
    i = ST s Word32 -> STT s m Word32
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word32 -> Int -> ST s Word32
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Word32
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Word32 -> Int -> Word32 -> STT s m ()
    unsafeWrite arr :: STUArray s i Word32
    arr i :: Int
    i e :: Word32
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word32 -> Int -> Word32 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Word32
    arr Int
    i Word32
    e)

    instance (Applicative m, Monad m) => MArray (STUArray s) Word64 (STT s m) where
        {-# INLINE getBounds #-}
        getBounds :: STUArray s i Word64 -> STT s m (i, i)
    getBounds arr :: STUArray s i Word64
    arr = ST s (i, i) -> STT s m (i, i)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word64 -> ST s (i, i)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m (i, i)
    getBounds STUArray s i Word64
    arr)
        {-# INLINE getNumElements #-}
        getNumElements :: STUArray s i Word64 -> STT s m Int
    getNumElements arr :: STUArray s i Word64
    arr = ST s Int -> STT s m Int
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word64 -> ST s Int
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> m Int
    getNumElements STUArray s i Word64
    arr)
        {-# INLINE newArray #-}
        newArray :: (i, i) -> Word64 -> STT s m (STUArray s i Word64)
    newArray bnds :: (i, i)
    bnds e :: Word64
    e = ST s (STUArray s i Word64) -> STT s m (STUArray s i Word64)
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST ((i, i) -> Word64 -> ST s (STUArray s i Word64)
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    (i, i) -> e -> m (a i e)
    newArray (i, i)
    bnds Word64
    e)
        {-# INLINE unsafeRead #-}
        unsafeRead :: STUArray s i Word64 -> Int -> STT s m Word64
    unsafeRead arr :: STUArray s i Word64
    arr i :: Int
    i = ST s Word64 -> STT s m Word64
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word64 -> Int -> ST s Word64
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> m e
    unsafeRead STUArray s i Word64
    arr Int
    i)
        {-# INLINE unsafeWrite #-}
        unsafeWrite :: STUArray s i Word64 -> Int -> Word64 -> STT s m ()
    unsafeWrite arr :: STUArray s i Word64
    arr i :: Int
    i e :: Word64
    e = ST s () -> STT s m ()
    forall (m :: * -> *) s a. Applicative m => ST s a -> STT s m a
    liftST (STUArray s i Word64 -> Int -> Word64 -> ST s ()
    forall (a :: * -> * -> *) e (m :: * -> *) i.
    (MArray a e m, Ix i) =>
    a i e -> Int -> e -> m ()
    unsafeWrite STUArray s i Word64
    arr Int
    i Word64
    e)