{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Concurrent.Class.MonadSTM.Strict.TArray
( StrictTArray
, LazyTArray
, toLazyTArray
, fromLazyTArray
) where
import Control.Concurrent.Class.MonadSTM.TArray qualified 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 = LazyTArray m i e -> StrictTArray m i e
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) = LazyTArray m i e -> stm (i, i)
forall i. Ix i => TArray m i e -> stm (i, i)
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 = LazyTArray m i e -> StrictTArray m i e
forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
StrictTArray (LazyTArray m i e -> StrictTArray m i e)
-> stm (LazyTArray m i e) -> stm (StrictTArray m i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (i, i) -> e -> stm (LazyTArray m i e)
forall i. Ix i => (i, i) -> e -> stm (TArray m i e)
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 = LazyTArray m i e -> StrictTArray m i e
forall (m :: * -> *) i e. LazyTArray m i e -> StrictTArray m i e
StrictTArray (LazyTArray m i e -> StrictTArray m i e)
-> stm (LazyTArray m i e) -> stm (StrictTArray m i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (i, i) -> stm (LazyTArray m i e)
forall i. Ix i => (i, i) -> stm (TArray m i e)
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 = LazyTArray m i e -> Int -> stm e
forall i. Ix i => TArray m i e -> Int -> stm e
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 = LazyTArray m i e -> Int -> e -> stm ()
forall i. Ix i => TArray m i e -> Int -> e -> stm ()
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) = LazyTArray m i e -> stm Int
forall i. Ix i => TArray m i e -> stm Int
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> m Int
getNumElements LazyTArray m i e
arr