Hoogle Search
Within LTS Haskell 24.50 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
primitive Data.Primitive.SmallArray Copy a slice of one mutable array into another. Note: this function does not do bounds or overlap checking.
createSmallArray :: Int -> a -> (forall s . () => SmallMutableArray s a -> ST s ()) -> SmallArray aprimitive Data.Primitive.SmallArray Create an array of the given size with a default value, apply the monadic function and freeze the result. If the size is 0, return emptySmallArray (rather than a new copy thereof).
createSmallArray 0 _ _ = emptySmallArray createSmallArray n x f = runSmallArray $ do mary <- newSmallArray n x f mary pure mary
emptySmallArray :: SmallArray aprimitive Data.Primitive.SmallArray The empty SmallArray.
-
primitive Data.Primitive.SmallArray Create an immutable array corresponding to a slice of a mutable array. This operation copies the portion of the array to be frozen. Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.
getSizeofSmallMutableArray :: PrimMonad m => SmallMutableArray (PrimState m) a -> m Intprimitive Data.Primitive.SmallArray Get the number of elements in a mutable array. Unlike sizeofSmallMutableArray, this function will be sure to produce the correct result if SmallMutableArray has been shrunk in place. Consider the following:
do sa <- newSmallArray 10 x print $ sizeofSmallMutableArray sa shrinkSmallMutableArray sa 5 print $ sizeofSmallMutableArray sa
The compiler is well within its rights to eliminate the second size check and print 10 twice. However, getSizeofSmallMutableArray will check the size each time it's executed (not evaluated), so it won't have this problem:do sa <- newSmallArray 10 x print =<< getSizeofSmallMutableArray sa shrinkSmallMutableArray sa 5 print =<< getSizeofSmallMutableArray sa
will certainly print 10 and then 5.indexSmallArray :: SmallArray a -> Int -> aprimitive Data.Primitive.SmallArray Look up an element in an immutable array. Note: this function does not do bounds checking.
indexSmallArray## :: SmallArray a -> Int -> (# a #)primitive Data.Primitive.SmallArray Read a value from the immutable array at the given index, returning the result in an unboxed unary tuple. This is currently used to implement folds. Note: this function does not do bounds checking.
indexSmallArrayM :: Applicative m => SmallArray a -> Int -> m aprimitive Data.Primitive.SmallArray Look up an element in an immutable array. The purpose of returning a result using an applicative is to allow the caller to avoid retaining references to the array. Evaluating the return value will cause the array lookup to be performed, even though it may not require the element of the array to be evaluated (which could throw an exception). For instance:
data Box a = Box a ... f sa = case indexSmallArrayM sa 0 of Box x -> ...
x is not a closure that references sa as it would be if we instead wrote:let x = indexSmallArray sa 0
It also does not prevent sa from being garbage collected. Note that Identity is not adequate for this use, as it is a newtype, and cannot be evaluated without evaluating the element. Note: this function does not do bounds checking.mapSmallArray' :: (a -> b) -> SmallArray a -> SmallArray bprimitive Data.Primitive.SmallArray Strict map over the elements of the array.
newSmallArray :: PrimMonad m => Int -> a -> m (SmallMutableArray (PrimState m) a)primitive Data.Primitive.SmallArray Create a new small mutable array. Note: this function does not check if the input is non-negative.