-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | primitive functions with bounds-checking -- -- This library is intended to be used as a drop-in replacement for the -- primitive library in test environments. It adds -- bounds-checking to all functions in primitive that are able -- to cause segfaults. It is not recommended to use this library in -- production. However, if you are testing a library or application you -- wrote that uses primitive, you can temporarily replace your -- primitive dependency with primitive-checked, and -- your segfaults will become normal Haskell exceptions that you can hunt -- down with GHC's stack trace facilities. -- -- The versioning for this library matches the version of -- primitive that is targeted. The first three numbers of the -- version match the version of primitive. The fourth number is -- used for bug fixes. This packages deviates slightly from the PVP in -- that functions can be added to the API with only a bump to the fourth -- number. @package primitive-checked @version 0.7.3.0 module Data.Primitive.Array -- | Boxed arrays. data Array a Array :: Array# a -> Array a [array#] :: Array a -> Array# a -- | Mutable boxed arrays associated with a primitive state token. data MutableArray s a MutableArray :: MutableArray# s a -> MutableArray s a [marray#] :: MutableArray s a -> MutableArray# s a newArray :: (HasCallStack, PrimMonad m) => Int -> a -> m (MutableArray (PrimState m) a) readArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> m a writeArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> a -> m () indexArray :: HasCallStack => Array a -> Int -> a indexArrayM :: (HasCallStack, Monad m) => Array a -> Int -> m a indexArray## :: HasCallStack => Array a -> Int -> (# a #) freezeArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> Int -> m (Array a) thawArray :: (HasCallStack, PrimMonad m) => Array a -> Int -> Int -> m (MutableArray (PrimState m) a) -- | Execute the monadic action and freeze the resulting array. -- --
-- runArray m = runST $ m >>= unsafeFreezeArray --runArray :: (forall s. () => ST s (MutableArray s a)) -> Array a createArray :: Int -> a -> (forall s. MutableArray s a -> ST s ()) -> Array a -- | This installs error thunks in the argument array so that any attempt -- to use it after an unsafeFreeze will fail. unsafeFreezeArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> m (Array a) -- | Convert an immutable array to an mutable one without copying. The -- immutable array should not be used after the conversion. unsafeThawArray :: PrimMonad m => Array a -> m (MutableArray (PrimState m) a) -- | Check whether the two arrays refer to the same memory block. sameMutableArray :: MutableArray s a -> MutableArray s a -> Bool copyArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> Array a -> Int -> Int -> m () copyMutableArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> MutableArray (PrimState m) a -> Int -> Int -> m () cloneArray :: HasCallStack => Array a -> Int -> Int -> Array a cloneMutableArray :: (HasCallStack, PrimMonad m) => MutableArray (PrimState m) a -> Int -> Int -> m (MutableArray (PrimState m) a) -- | The number of elements in an immutable array. sizeofArray :: Array a -> Int -- | The number of elements in a mutable array. sizeofMutableArray :: MutableArray s a -> Int -- | The empty Array. emptyArray :: Array a -- | The fromListN function takes the input list's length as a hint. -- Its behaviour should be equivalent to fromList. The hint can be -- used to construct the structure l more efficiently compared -- to fromList. If the given hint does not equal to the input -- list's length the behaviour of fromListN is not specified. fromListN :: IsList l => Int -> [Item l] -> l -- | The fromList function constructs the structure l from -- the given list of Item l fromList :: IsList l => [Item l] -> l -- | Create an array from a list of a known length. If the length of the -- list does not match the given length, this throws an exception. arrayFromListN :: Int -> [a] -> Array a -- | Create an array from a list. arrayFromList :: [a] -> Array a -- | Strict map over the elements of the array. mapArray' :: (a -> b) -> Array a -> Array b -- | This is the fastest, most straightforward way to traverse an array, -- but it only works correctly with a sufficiently "affine" -- PrimMonad instance. In particular, it must only produce -- one result array. ListT-transformed monads, for example, -- will not work right at all. traverseArrayP :: PrimMonad m => (a -> m b) -> Array a -> m (Array b) module Data.Primitive.ByteArray -- | Byte arrays. data ByteArray ByteArray :: ByteArray# -> ByteArray -- | Mutable byte arrays associated with a primitive state token. data MutableByteArray s MutableByteArray :: MutableByteArray# s -> MutableByteArray s data ByteArray# :: TYPE 'UnliftedRep data MutableByteArray# a :: TYPE 'UnliftedRep newByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m)) newPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m)) newAlignedPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> Int -> m (MutableByteArray (PrimState m)) -- | After a call to resizeMutableByteArray, the original reference -- to the mutable array should not be used again. This cannot truly be -- enforced except by linear types. To attempt to enforce this, we always -- make a copy of the mutable primitive array and intentionally corrupt -- the original of the original one. The strategy used here to corrupt -- the array is simply to write 0xFF to every byte. resizeMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m (MutableByteArray (PrimState m)) shrinkMutableByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m () readByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m a writeByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> a -> m () indexByteArray :: forall a. (HasCallStack, Prim a) => ByteArray -> Int -> a -- | The empty ByteArray. emptyByteArray :: ByteArray -- | Create a ByteArray from a list. -- --
-- byteArrayFromList xs = byteArrayFromListN (length xs) xs --byteArrayFromList :: Prim a => [a] -> ByteArray -- | Create a ByteArray from a list of a known length. If the length -- of the list does not match the given length, this throws an exception. byteArrayFromListN :: Prim a => Int -> [a] -> ByteArray -- | Right-fold over the elements of a ByteArray. foldrByteArray :: Prim a => (a -> b -> b) -> b -> ByteArray -> b compareByteArrays :: ByteArray -> Int -> ByteArray -> Int -> Int -> Ordering freezeByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> m ByteArray thawByteArray :: (HasCallStack, PrimMonad m) => ByteArray -> Int -> Int -> m (MutableByteArray (PrimState m)) -- | Execute the monadic action and freeze the resulting array. -- --
-- runByteArray m = runST $ m >>= unsafeFreezeByteArray --runByteArray :: (forall s. () => ST s (MutableByteArray s)) -> ByteArray -- | This corrupts the contents of the argument array by writing -- 0xFF to every byte. unsafeFreezeByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> m ByteArray -- | Convert an immutable byte array to a mutable one without copying. The -- original array should not be used after the conversion. unsafeThawByteArray :: PrimMonad m => ByteArray -> m (MutableByteArray (PrimState m)) copyByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> ByteArray -> Int -> Int -> m () copyMutableByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () copyByteArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> ByteArray -> Int -> Int -> m () copyMutableByteArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> MutableByteArray (PrimState m) -> Int -> Int -> m () copyByteArrayToAddr :: (HasCallStack, PrimMonad m) => Ptr Word8 -> ByteArray -> Int -> Int -> m () copyMutableByteArrayToAddr :: (HasCallStack, PrimMonad m) => Ptr Word8 -> MutableByteArray (PrimState m) -> Int -> Int -> m () moveByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () setByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> a -> m () fillByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> Word8 -> m () cloneByteArray :: HasCallStack => ByteArray -> Int -> Int -> ByteArray cloneMutableByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> m (MutableByteArray (PrimState m)) -- | Size of the byte array in bytes. sizeofByteArray :: ByteArray -> Int -- | Size of the mutable byte array in bytes. This function's behavior is -- undefined if resizeMutableByteArray is ever called on the -- mutable byte array given as the argument. Consequently, use of this -- function is discouraged. Prefer getSizeofMutableByteArray, -- which ensures correct sequencing in the presence of resizing. sizeofMutableByteArray :: MutableByteArray s -> Int -- | Get the size of a byte array in bytes. Unlike -- sizeofMutableByteArray, this function ensures sequencing in the -- presence of resizing. getSizeofMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m Int -- | Check if the two arrays refer to the same memory block. sameMutableByteArray :: MutableByteArray s -> MutableByteArray s -> Bool -- | Check whether or not the byte array is pinned. Pinned byte arrays -- cannot be moved by the garbage collector. It is safe to use -- byteArrayContents on such byte arrays. This function is only -- available when compiling with GHC 8.2 or newer. isByteArrayPinned :: ByteArray -> Bool -- | Check whether or not the mutable byte array is pinned. This function -- is only available when compiling with GHC 8.2 or newer. isMutableByteArrayPinned :: MutableByteArray s -> Bool -- | Yield a pointer to the array's data. This operation is only safe on -- pinned byte arrays allocated by newPinnedByteArray or -- newAlignedPinnedByteArray. byteArrayContents :: ByteArray -> Ptr Word8 -- | Yield a pointer to the array's data. This operation is only safe on -- pinned byte arrays allocated by newPinnedByteArray or -- newAlignedPinnedByteArray. mutableByteArrayContents :: MutableByteArray s -> Ptr Word8 module Data.Primitive.PrimArray -- | Arrays of unboxed elements. This accepts types like Double, -- Char, Int and Word, as well as their fixed-length -- variants (Word8, Word16, etc.). Since the elements -- are unboxed, a PrimArray is strict in its elements. This -- differs from the behavior of Array, which is lazy in its -- elements. data PrimArray a PrimArray :: ByteArray# -> PrimArray a -- | Mutable primitive arrays associated with a primitive state token. -- These can be written to and read from in a monadic context that -- supports sequencing, such as IO or ST. Typically, a -- mutable primitive array will be built and then converted to an -- immutable primitive array using unsafeFreezePrimArray. However, -- it is also acceptable to simply discard a mutable primitive array -- since it lives in managed memory and will be garbage collected when no -- longer referenced. data MutablePrimArray s a MutablePrimArray :: MutableByteArray# s -> MutablePrimArray s a newPrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) newPinnedPrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) newAlignedPinnedPrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) -- | After a call to resizeMutablePrimArray, the original reference -- to the mutable array should not be used again. This cannot truly be -- enforced except by linear types. To attempt to enforce this, we always -- make a copy of the mutable primitive array and intentionally corrupt -- the original of the original one. The strategy used here to corrupt -- the array is simply to write 0xFF to every byte. resizeMutablePrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> m (MutablePrimArray (PrimState m) a) shrinkMutablePrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> m () readPrimArray :: (HasCallStack, Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> m a writePrimArray :: (HasCallStack, Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> a -> m () indexPrimArray :: forall a. Prim a => PrimArray a -> Int -> a freezePrimArray :: (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> Int -> m (PrimArray a) thawPrimArray :: (HasCallStack, PrimMonad m, Prim a) => PrimArray a -> Int -> Int -> m (MutablePrimArray (PrimState m) a) -- | Execute the monadic action and freeze the resulting array. -- --
-- runPrimArray m = runST $ m >>= unsafeFreezePrimArray --runPrimArray :: (forall s. () => ST s (MutablePrimArray s a)) -> PrimArray a -- | This corrupts the contents of the argument array by writing -- 0xFF to every byte. unsafeFreezePrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> m (PrimArray a) -- | Convert an immutable array to a mutable one without copying. The -- original array should not be used after the conversion. unsafeThawPrimArray :: PrimMonad m => PrimArray a -> m (MutablePrimArray (PrimState m) a) copyPrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> PrimArray a -> Int -> Int -> m () copyMutablePrimArray :: forall m a. (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> MutablePrimArray (PrimState m) a -> Int -> Int -> m () copyPrimArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> PrimArray a -> Int -> Int -> m () copyMutablePrimArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m () clonePrimArray :: (HasCallStack, Prim a) => PrimArray a -> Int -> Int -> PrimArray a cloneMutablePrimArray :: (HasCallStack, PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> Int -> m (MutablePrimArray (PrimState m) a) setPrimArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> Int -> a -> m () -- | Check if the two arrays refer to the same memory block. sameMutablePrimArray :: MutablePrimArray s a -> MutablePrimArray s a -> Bool -- | Get the size of a mutable primitive array in elements. Unlike -- sizeofMutablePrimArray, this function ensures sequencing in the -- presence of resizing. getSizeofMutablePrimArray :: (PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> m Int -- | Size of the mutable primitive array in elements. This function shall -- not be used on primitive arrays that are an argument to or a result of -- resizeMutablePrimArray or shrinkMutablePrimArray. sizeofMutablePrimArray :: forall s a. Prim a => MutablePrimArray s a -> Int -- | Get the size, in elements, of the primitive array. sizeofPrimArray :: Prim a => PrimArray a -> Int -- | Yield a pointer to the array's data. This operation is only safe on -- pinned prim arrays allocated by newPinnedByteArray or -- newAlignedPinnedByteArray. primArrayContents :: PrimArray a -> Ptr a -- | Yield a pointer to the array's data. This operation is only safe on -- pinned byte arrays allocated by newPinnedByteArray or -- newAlignedPinnedByteArray. mutablePrimArrayContents :: MutablePrimArray s a -> Ptr a -- | Check whether or not the primitive array is pinned. Pinned primitive -- arrays cannot be moved by the garbage collector. It is safe to use -- primArrayContents on such arrays. This function is only -- available when compiling with GHC 8.2 or newer. isPrimArrayPinned :: PrimArray a -> Bool -- | Check whether or not the mutable primitive array is pinned. This -- function is only available when compiling with GHC 8.2 or newer. isMutablePrimArrayPinned :: MutablePrimArray s a -> Bool -- | Convert a PrimArray to a list. primArrayToList :: Prim a => PrimArray a -> [a] -- | Create a PrimArray from a list. -- --
-- primArrayFromList vs = primArrayFromListN (length vs) vs --primArrayFromList :: Prim a => [a] -> PrimArray a -- | Create a PrimArray from a list of a known length. If the length -- of the list does not match the given length, this throws an exception. primArrayFromListN :: Prim a => Int -> [a] -> PrimArray a -- | Lazy right-associated fold over the elements of a PrimArray. foldrPrimArray :: Prim a => (a -> b -> b) -> b -> PrimArray a -> b -- | Strict right-associated fold over the elements of a PrimArray. foldrPrimArray' :: Prim a => (a -> b -> b) -> b -> PrimArray a -> b -- | Lazy left-associated fold over the elements of a PrimArray. foldlPrimArray :: Prim a => (b -> a -> b) -> b -> PrimArray a -> b -- | Strict left-associated fold over the elements of a PrimArray. foldlPrimArray' :: Prim a => (b -> a -> b) -> b -> PrimArray a -> b -- | Strict left-associated fold over the elements of a PrimArray. foldlPrimArrayM' :: (Prim a, Monad m) => (b -> a -> m b) -> b -> PrimArray a -> m b -- | Traverse the primitive array, discarding the results. There is no -- PrimMonad variant of this function, since it would not provide -- any performance benefit. traversePrimArray_ :: (Applicative f, Prim a) => (a -> f b) -> PrimArray a -> f () -- | Traverse the primitive array with the indices, discarding the results. -- There is no PrimMonad variant of this function, since it would -- not provide any performance benefit. itraversePrimArray_ :: (Applicative f, Prim a) => (Int -> a -> f b) -> PrimArray a -> f () -- | The empty PrimArray. emptyPrimArray :: PrimArray a -- | Map over the elements of a primitive array. mapPrimArray :: (Prim a, Prim b) => (a -> b) -> PrimArray a -> PrimArray b -- | Indexed map over the elements of a primitive array. imapPrimArray :: (Prim a, Prim b) => (Int -> a -> b) -> PrimArray a -> PrimArray b -- | Generate a primitive array. generatePrimArray :: Prim a => Int -> (Int -> a) -> PrimArray a -- | Create a primitive array by copying the element the given number of -- times. replicatePrimArray :: Prim a => Int -> a -> PrimArray a -- | Filter elements of a primitive array according to a predicate. filterPrimArray :: Prim a => (a -> Bool) -> PrimArray a -> PrimArray a -- | Map over a primitive array, optionally discarding some elements. This -- has the same behavior as Data.Maybe.mapMaybe. mapMaybePrimArray :: (Prim a, Prim b) => (a -> Maybe b) -> PrimArray a -> PrimArray b -- | Traverse a primitive array. The traversal performs all of the -- applicative effects before forcing the resulting values and -- writing them to the new primitive array. Consequently: -- --
-- >>> traversePrimArray (\x -> print x $> bool x undefined (x == 2)) (fromList [1, 2, 3 :: Int]) -- 1 -- 2 -- 3 -- *** Exception: Prelude.undefined ---- -- The function traversePrimArrayP always outperforms this -- function, but it requires a PrimMonad constraint, and it forces -- the values as it performs the effects. traversePrimArray :: (Applicative f, Prim a, Prim b) => (a -> f b) -> PrimArray a -> f (PrimArray b) -- | Traverse a primitive array with the index of each element. itraversePrimArray :: (Applicative f, Prim a, Prim b) => (Int -> a -> f b) -> PrimArray a -> f (PrimArray b) -- | Generate a primitive array by evaluating the applicative generator -- function at each index. generatePrimArrayA :: (Applicative f, Prim a) => Int -> (Int -> f a) -> f (PrimArray a) -- | Execute the applicative action the given number of times and store the -- results in a PrimArray. replicatePrimArrayA :: (Applicative f, Prim a) => Int -> f a -> f (PrimArray a) -- | Filter the primitive array, keeping the elements for which the monadic -- predicate evaluates true. filterPrimArrayA :: (Applicative f, Prim a) => (a -> f Bool) -> PrimArray a -> f (PrimArray a) -- | Map over the primitive array, keeping the elements for which the -- applicative predicate provides a Just. mapMaybePrimArrayA :: (Applicative f, Prim a, Prim b) => (a -> f (Maybe b)) -> PrimArray a -> f (PrimArray b) -- | Traverse a primitive array. The traversal forces the resulting values -- and writes them to the new primitive array as it performs the monadic -- effects. Consequently: -- --
-- >>> traversePrimArrayP (\x -> print x $> bool x undefined (x == 2)) (fromList [1, 2, 3 :: Int]) -- 1 -- 2 -- *** Exception: Prelude.undefined ---- -- In many situations, traversePrimArrayP can replace -- traversePrimArray, changing the strictness characteristics of -- the traversal but typically improving the performance. Consider the -- following short-circuiting traversal: -- --
-- incrPositiveA :: PrimArray Int -> Maybe (PrimArray Int) -- incrPositiveA xs = traversePrimArray (\x -> bool Nothing (Just (x + 1)) (x > 0)) xs ---- -- This can be rewritten using traversePrimArrayP. To do this, we -- must change the traversal context to MaybeT (ST s), which has -- a PrimMonad instance: -- --
-- incrPositiveB :: PrimArray Int -> Maybe (PrimArray Int) -- incrPositiveB xs = runST $ runMaybeT $ traversePrimArrayP -- (\x -> bool (MaybeT (return Nothing)) (MaybeT (return (Just (x + 1)))) (x > 0)) -- xs ---- -- Benchmarks demonstrate that the second implementation runs 150 times -- faster than the first. It also results in fewer allocations. traversePrimArrayP :: (PrimMonad m, Prim a, Prim b) => (a -> m b) -> PrimArray a -> m (PrimArray b) -- | Traverse a primitive array with the indices. The traversal forces the -- resulting values and writes them to the new primitive array as it -- performs the monadic effects. itraversePrimArrayP :: (Prim a, Prim b, PrimMonad m) => (Int -> a -> m b) -> PrimArray a -> m (PrimArray b) -- | Generate a primitive array by evaluating the monadic generator -- function at each index. generatePrimArrayP :: (PrimMonad m, Prim a) => Int -> (Int -> m a) -> m (PrimArray a) -- | Execute the monadic action the given number of times and store the -- results in a primitive array. replicatePrimArrayP :: (PrimMonad m, Prim a) => Int -> m a -> m (PrimArray a) -- | Filter the primitive array, keeping the elements for which the monadic -- predicate evaluates to true. filterPrimArrayP :: (PrimMonad m, Prim a) => (a -> m Bool) -> PrimArray a -> m (PrimArray a) -- | Map over the primitive array, keeping the elements for which the -- monadic predicate provides a Just. mapMaybePrimArrayP :: (PrimMonad m, Prim a, Prim b) => (a -> m (Maybe b)) -> PrimArray a -> m (PrimArray b) module Data.Primitive.SmallArray data SmallArray a SmallArray :: SmallArray# a -> SmallArray a data SmallMutableArray s a SmallMutableArray :: SmallMutableArray# s a -> SmallMutableArray s a newSmallArray :: (HasCallStack, PrimMonad m) => Int -> a -> m (SmallMutableArray (PrimState m) a) readSmallArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> m a writeSmallArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> a -> m () copySmallArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> SmallArray a -> Int -> Int -> m () copySmallMutableArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> SmallMutableArray (PrimState m) a -> Int -> Int -> m () indexSmallArray :: HasCallStack => SmallArray a -> Int -> a indexSmallArrayM :: (HasCallStack, Monad m) => SmallArray a -> Int -> m a indexSmallArray## :: HasCallStack => SmallArray a -> Int -> (# a #) cloneSmallArray :: HasCallStack => SmallArray a -> Int -> Int -> SmallArray a cloneSmallMutableArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> Int -> m (SmallMutableArray (PrimState m) a) freezeSmallArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> Int -> m (SmallArray a) -- | This installs error thunks in the argument array so that any attempt -- to use it after an unsafeFreeze will fail. unsafeFreezeSmallArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> m (SmallArray a) thawSmallArray :: (HasCallStack, PrimMonad m) => SmallArray a -> Int -> Int -> m (SmallMutableArray (PrimState m) a) -- | Render an immutable array mutable. -- -- This operation performs no copying, so care must be taken with its -- use. unsafeThawSmallArray :: PrimMonad m => SmallArray a -> m (SmallMutableArray (PrimState m) a) -- | Execute the monadic action and freeze the resulting array. -- --
-- runSmallArray m = runST $ m >>= unsafeFreezeSmallArray --runSmallArray :: (forall s. () => ST s (SmallMutableArray s a)) -> SmallArray a createSmallArray :: Int -> a -> (forall s. SmallMutableArray s a -> ST s ()) -> SmallArray a -- | The number of elements in an immutable array. sizeofSmallArray :: SmallArray a -> Int -- | The number of elements in a mutable array. sizeofSmallMutableArray :: SmallMutableArray s a -> Int shrinkSmallMutableArray :: (HasCallStack, PrimMonad m) => SmallMutableArray (PrimState m) a -> Int -> m () -- | The empty SmallArray. emptySmallArray :: SmallArray a -- | Create a SmallArray from a list. smallArrayFromList :: [a] -> SmallArray a -- | Create a SmallArray from a list of a known length. If the -- length of the list does not match the given length, this throws an -- exception. smallArrayFromListN :: Int -> [a] -> SmallArray a -- | Strict map over the elements of the array. mapSmallArray' :: (a -> b) -> SmallArray a -> SmallArray b -- | This is the fastest, most straightforward way to traverse an array, -- but it only works correctly with a sufficiently "affine" -- PrimMonad instance. In particular, it must only produce -- one result array. ListT-transformed monads, for example, -- will not work right at all. traverseSmallArrayP :: PrimMonad m => (a -> m b) -> SmallArray a -> m (SmallArray b) module Data.Primitive