{-# LANGUAGE Rank2Types #-}
module Data.StorableVector.ST.Lazy (
Vector,
new,
new_,
read,
write,
modify,
unsafeRead,
unsafeWrite,
unsafeModify,
freeze,
unsafeFreeze,
thaw,
VST.length,
runSTVector,
mapST,
mapSTLazy,
) where
import qualified Data.StorableVector as VS
import qualified Data.StorableVector.Lazy as VL
import qualified Data.StorableVector.ST.Strict as VST
import Data.StorableVector.ST.Strict (Vector)
import qualified Control.Monad.ST.Lazy as ST
import Control.Monad.ST.Lazy (ST)
import Foreign.Storable (Storable)
import Prelude hiding (read, length, )
{-# INLINE new #-}
new :: (Storable e) =>
Int -> e -> ST s (Vector s e)
new n x = ST.strictToLazyST (VST.new n x)
{-# INLINE new_ #-}
new_ :: (Storable e) =>
Int -> ST s (Vector s e)
new_ n = ST.strictToLazyST (VST.new_ n)
{-# INLINE read #-}
read :: (Storable e) =>
Vector s e -> Int -> ST s e
read xs n = ST.strictToLazyST (VST.read xs n)
{-# INLINE write #-}
write :: (Storable e) =>
Vector s e -> Int -> e -> ST s ()
write xs n x = ST.strictToLazyST (VST.write xs n x)
{-# INLINE modify #-}
modify :: (Storable e) =>
Vector s e -> Int -> (e -> e) -> ST s ()
modify xs n f = ST.strictToLazyST (VST.modify xs n f)
{-# INLINE unsafeRead #-}
unsafeRead :: (Storable e) =>
Vector s e -> Int -> ST s e
unsafeRead xs n = ST.strictToLazyST (VST.unsafeRead xs n)
{-# INLINE unsafeWrite #-}
unsafeWrite :: (Storable e) =>
Vector s e -> Int -> e -> ST s ()
unsafeWrite xs n x = ST.strictToLazyST (VST.unsafeWrite xs n x)
{-# INLINE unsafeModify #-}
unsafeModify :: (Storable e) =>
Vector s e -> Int -> (e -> e) -> ST s ()
unsafeModify xs n f = ST.strictToLazyST (VST.unsafeModify xs n f)
{-# INLINE freeze #-}
freeze :: (Storable e) =>
Vector s e -> ST s (VS.Vector e)
freeze xs = ST.strictToLazyST (VST.freeze xs)
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: (Storable e) =>
Vector s e -> ST s (VS.Vector e)
unsafeFreeze xs = ST.strictToLazyST (VST.unsafeFreeze xs)
{-# INLINE thaw #-}
thaw :: (Storable e) =>
VS.Vector e -> ST s (Vector s e)
thaw xs = ST.strictToLazyST (VST.thaw xs)
{-# INLINE runSTVector #-}
runSTVector :: (Storable e) =>
(forall s. ST s (Vector s e)) -> VS.Vector e
runSTVector m = VST.runSTVector (ST.lazyToStrictST m)
{-# INLINE mapST #-}
mapST :: (Storable a, Storable b) =>
(a -> ST s b) -> VS.Vector a -> ST s (VS.Vector b)
mapST f xs =
ST.strictToLazyST (VST.mapST (ST.lazyToStrictST . f) xs)
{-# INLINE mapSTLazy #-}
mapSTLazy :: (Storable a, Storable b) =>
(a -> ST s b) -> VL.Vector a -> ST s (VL.Vector b)
mapSTLazy f (VL.SV xs) =
fmap VL.SV $ mapM (mapST f) xs