{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE ExplicitNamespaces    #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances  #-}

-- | This module corresponds to `Control.Concurrent.STM.TArray` in "stm" package
--
module Control.Concurrent.Class.MonadSTM.Strict.TArray
  ( StrictTArray
  , LazyTArray
  , toLazyTArray
  , fromLazyTArray
  ) where


import qualified Control.Concurrent.Class.MonadSTM.TArray as Lazy

import           Data.Array.Base (MArray (..))


type LazyTArray  m = Lazy.TArray m

newtype StrictTArray m i e = StrictTArray { forall (m :: * -> *) i e. StrictTArray m i e -> LazyTArray m i e
toLazyTArray :: LazyTArray m i e }

fromLazyTArray :: LazyTArray m i e -> StrictTArray m i e
fromLazyTArray :: forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
fromLazyTArray = forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
StrictTArray

instance ( MArray (Lazy.TArray m) e stm
         , Monad stm
         )
      => MArray (StrictTArray m) e stm where
    getBounds :: forall i. Ix i => StrictTArray m i e -> stm (i, i)
getBounds (StrictTArray LazyTArray m i e
arr) = forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> m (i, i)
getBounds LazyTArray m i e
arr
    newArray :: forall i. Ix i => (i, i) -> e -> stm (StrictTArray m i e)
newArray  (i, i)
b !e
e = forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
StrictTArray forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (i, i)
b e
e
    newArray_ :: forall i. Ix i => (i, i) -> stm (StrictTArray m i e)
newArray_ (i, i)
b    = forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
StrictTArray forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> m (a i e)
newArray_ (i, i)
b
    unsafeRead :: forall i. Ix i => StrictTArray m i e -> Int -> stm e
unsafeRead     (StrictTArray LazyTArray m i e
arr) Int
i    = forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> Int -> m e
unsafeRead LazyTArray m i e
arr Int
i
    unsafeWrite :: forall i. Ix i => StrictTArray m i e -> Int -> e -> stm ()
unsafeWrite    (StrictTArray LazyTArray m i e
arr) Int
i !e
e = forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> Int -> e -> m ()
unsafeWrite LazyTArray m i e
arr Int
i e
e
    getNumElements :: forall i. Ix i => StrictTArray m i e -> stm Int
getNumElements (StrictTArray LazyTArray m i e
arr)      = forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> m Int
getNumElements LazyTArray m i e
arr