unison-runtime-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Runtime.Array

Synopsis

Documentation

data ByteArray# :: UnliftedType #

A boxed, unlifted datatype representing a region of raw memory in the garbage-collected heap, which is not scanned for pointers during garbage collection.

It is created by freezing a MutableByteArray# with unsafeFreezeByteArray#. Freezing is essentially a no-op, as MutableByteArray# and ByteArray# share the same heap structure under the hood.

The immutable and mutable variants are commonly used for scenarios requiring high-performance data structures, like Text, Primitive Vector, Unboxed Array, and ShortByteString.

Another application of fundamental importance is Integer, which is backed by ByteArray#.

The representation on the heap of a Byte Array is:

+------------+-----------------+-----------------------+
|            |                 |                       |
|   HEADER   | SIZE (in bytes) |       PAYLOAD         |
|            |                 |                       |
+------------+-----------------+-----------------------+

To obtain a pointer to actual payload (e.g., for FFI purposes) use byteArrayContents# or mutableByteArrayContents#.

Alternatively, enabling the UnliftedFFITypes extension allows to mention ByteArray# and MutableByteArray# in FFI type signatures directly.

data MutableByteArray# a :: UnliftedType #

A mutable ByteAray#. It can be created in three ways:

Unpinned arrays can be moved around during garbage collection, so you must not store or pass pointers to these values if there is a chance for the garbage collector to kick in. That said, even unpinned arrays can be passed to unsafe FFI calls, because no garbage collection happens during these unsafe calls (see Guaranteed Call Safety in the GHC Manual). For safe FFI calls, byte arrays must be not only pinned, but also kept alive by means of the keepAlive# function for the duration of a call (that's because garbage collection cannot move a pinned array, but is free to scrap it altogether).

data Array a #

Boxed arrays.

Constructors

Array 

Fields

Instances

Instances details
MonadFail Array 
Instance details

Defined in Data.Primitive.Array

Methods

fail :: String -> Array a #

MonadFix Array 
Instance details

Defined in Data.Primitive.Array

Methods

mfix :: (a -> Array a) -> Array a #

MonadZip Array 
Instance details

Defined in Data.Primitive.Array

Methods

mzip :: Array a -> Array b -> Array (a, b) #

mzipWith :: (a -> b -> c) -> Array a -> Array b -> Array c #

munzip :: Array (a, b) -> (Array a, Array b) #

Foldable Array 
Instance details

Defined in Data.Primitive.Array

Methods

fold :: Monoid m => Array m -> m #

foldMap :: Monoid m => (a -> m) -> Array a -> m #

foldMap' :: Monoid m => (a -> m) -> Array a -> m #

foldr :: (a -> b -> b) -> b -> Array a -> b #

foldr' :: (a -> b -> b) -> b -> Array a -> b #

foldl :: (b -> a -> b) -> b -> Array a -> b #

foldl' :: (b -> a -> b) -> b -> Array a -> b #

foldr1 :: (a -> a -> a) -> Array a -> a #

foldl1 :: (a -> a -> a) -> Array a -> a #

toList :: Array a -> [a] #

null :: Array a -> Bool #

length :: Array a -> Int #

elem :: Eq a => a -> Array a -> Bool #

maximum :: Ord a => Array a -> a #

minimum :: Ord a => Array a -> a #

sum :: Num a => Array a -> a #

product :: Num a => Array a -> a #

Eq1 Array

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.Array

Methods

liftEq :: (a -> b -> Bool) -> Array a -> Array b -> Bool #

Ord1 Array

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.Array

Methods

liftCompare :: (a -> b -> Ordering) -> Array a -> Array b -> Ordering #

Read1 Array

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.Array

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Array a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Array a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Array a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Array a] #

Show1 Array

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.Array

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Array a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Array a] -> ShowS #

Traversable Array 
Instance details

Defined in Data.Primitive.Array

Methods

traverse :: Applicative f => (a -> f b) -> Array a -> f (Array b) #

sequenceA :: Applicative f => Array (f a) -> f (Array a) #

mapM :: Monad m => (a -> m b) -> Array a -> m (Array b) #

sequence :: Monad m => Array (m a) -> m (Array a) #

Alternative Array 
Instance details

Defined in Data.Primitive.Array

Methods

empty :: Array a #

(<|>) :: Array a -> Array a -> Array a #

some :: Array a -> Array [a] #

many :: Array a -> Array [a] #

Applicative Array 
Instance details

Defined in Data.Primitive.Array

Methods

pure :: a -> Array a #

(<*>) :: Array (a -> b) -> Array a -> Array b #

liftA2 :: (a -> b -> c) -> Array a -> Array b -> Array c #

(*>) :: Array a -> Array b -> Array b #

(<*) :: Array a -> Array b -> Array a #

Functor Array 
Instance details

Defined in Data.Primitive.Array

Methods

fmap :: (a -> b) -> Array a -> Array b #

(<$) :: a -> Array b -> Array a #

Monad Array 
Instance details

Defined in Data.Primitive.Array

Methods

(>>=) :: Array a -> (a -> Array b) -> Array b #

(>>) :: Array a -> Array b -> Array b #

return :: a -> Array a #

MonadPlus Array 
Instance details

Defined in Data.Primitive.Array

Methods

mzero :: Array a #

mplus :: Array a -> Array a -> Array a #

NFData1 Array 
Instance details

Defined in Data.Primitive.Array

Methods

liftRnf :: (a -> ()) -> Array a -> () #

Lift a => Lift (Array a :: Type) 
Instance details

Defined in Data.Primitive.Array

Methods

lift :: Quote m => Array a -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Array a -> Code m (Array a) #

Data a => Data (Array a) 
Instance details

Defined in Data.Primitive.Array

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array a -> c (Array a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array a) #

toConstr :: Array a -> Constr #

dataTypeOf :: Array a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Array a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Array a)) #

gmapT :: (forall b. Data b => b -> b) -> Array a -> Array a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Array a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Array a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) #

Monoid (Array a) 
Instance details

Defined in Data.Primitive.Array

Methods

mempty :: Array a #

mappend :: Array a -> Array a -> Array a #

mconcat :: [Array a] -> Array a #

Semigroup (Array a)

Since: primitive-0.6.3.0

Instance details

Defined in Data.Primitive.Array

Methods

(<>) :: Array a -> Array a -> Array a #

sconcat :: NonEmpty (Array a) -> Array a #

stimes :: Integral b => b -> Array a -> Array a #

IsList (Array a) 
Instance details

Defined in Data.Primitive.Array

Associated Types

type Item (Array a) #

Methods

fromList :: [Item (Array a)] -> Array a #

fromListN :: Int -> [Item (Array a)] -> Array a #

toList :: Array a -> [Item (Array a)] #

Read a => Read (Array a) 
Instance details

Defined in Data.Primitive.Array

Show a => Show (Array a) 
Instance details

Defined in Data.Primitive.Array

Methods

showsPrec :: Int -> Array a -> ShowS #

show :: Array a -> String #

showList :: [Array a] -> ShowS #

NFData a => NFData (Array a) 
Instance details

Defined in Data.Primitive.Array

Methods

rnf :: Array a -> () #

Eq a => Eq (Array a) 
Instance details

Defined in Data.Primitive.Array

Methods

(==) :: Array a -> Array a -> Bool #

(/=) :: Array a -> Array a -> Bool #

Ord a => Ord (Array a)

Lexicographic ordering. Subject to change between major versions.

Instance details

Defined in Data.Primitive.Array

Methods

compare :: Array a -> Array a -> Ordering #

(<) :: Array a -> Array a -> Bool #

(<=) :: Array a -> Array a -> Bool #

(>) :: Array a -> Array a -> Bool #

(>=) :: Array a -> Array a -> Bool #

max :: Array a -> Array a -> Array a #

min :: Array a -> Array a -> Array a #

ForeignConvention (Array RClosure) Source # 
Instance details

Defined in Unison.Runtime.Foreign.Function

Methods

readForeign :: [Int] -> [Int] -> Stack 'UN -> Stack 'BX -> IO ([Int], [Int], Array RClosure) Source #

writeForeign :: Stack 'UN -> Stack 'BX -> Array RClosure -> IO (Stack 'UN, Stack 'BX) Source #

type Item (Array a) 
Instance details

Defined in Data.Primitive.Array

type Item (Array a) = a

data MutableByteArray s #

Lifted wrapper for MutableByteArray#.

Since MutableByteArray# is an unlifted type and not a member of kind Type, things like [MutableByteArray#] or IO MutableByteArray# are ill-typed. To work around this inconvenience this module provides a standard lifted wrapper, inhabiting Type. Clients are expected to use MutableByteArray in higher-level APIs, but wrap and unwrap MutableByteArray internally as they please and use functions from GHC.Exts.

Since: base-4.17.0.0

Instances

Instances details
Typeable s => Data (MutableByteArray s)

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MutableByteArray s -> c (MutableByteArray s) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (MutableByteArray s) #

toConstr :: MutableByteArray s -> Constr #

dataTypeOf :: MutableByteArray s -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (MutableByteArray s)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (MutableByteArray s)) #

gmapT :: (forall b. Data b => b -> b) -> MutableByteArray s -> MutableByteArray s #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MutableByteArray s -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MutableByteArray s -> r #

gmapQ :: (forall d. Data d => d -> u) -> MutableByteArray s -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> MutableByteArray s -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) #

NFData (MutableByteArray s)

Since: deepseq-1.4.8.0

Instance details

Defined in Control.DeepSeq

Methods

rnf :: MutableByteArray s -> () #

Eq (MutableByteArray s)

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

ForeignConvention (MutableByteArray s) Source # 
Instance details

Defined in Unison.Runtime.Foreign.Function

data ByteArray #

Lifted wrapper for ByteArray#.

Since ByteArray# is an unlifted type and not a member of kind Type, things like [ByteArray#] or IO ByteArray# are ill-typed. To work around this inconvenience this module provides a standard lifted wrapper, inhabiting Type. Clients are expected to use ByteArray in higher-level APIs, but wrap and unwrap ByteArray internally as they please and use functions from GHC.Exts.

Since: base-4.17.0.0

Constructors

ByteArray ByteArray# 

Instances

Instances details
Data ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteArray -> c ByteArray #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteArray #

toConstr :: ByteArray -> Constr #

dataTypeOf :: ByteArray -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteArray) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteArray) #

gmapT :: (forall b. Data b => b -> b) -> ByteArray -> ByteArray #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteArray -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteArray -> r #

gmapQ :: (forall d. Data d => d -> u) -> ByteArray -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteArray -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray #

Monoid ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Semigroup ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

IsList ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Associated Types

type Item ByteArray #

Show ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

NFData ByteArray

Since: deepseq-1.4.7.0

Instance details

Defined in Control.DeepSeq

Methods

rnf :: ByteArray -> () #

Eq ByteArray

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Ord ByteArray

Non-lexicographic ordering. This compares the lengths of the byte arrays first and uses a lexicographic ordering if the lengths are equal. Subject to change between major versions.

Since: base-4.17.0.0

Instance details

Defined in Data.Array.Byte

Hashable ByteArray

This instance was available since 1.4.1.0 only for GHC-9.4+

Since: hashable-1.4.2.0

Instance details

Defined in Data.Hashable.Class

ForeignConvention ByteArray Source # 
Instance details

Defined in Unison.Runtime.Foreign.Function

Methods

readForeign :: [Int] -> [Int] -> Stack 'UN -> Stack 'BX -> IO ([Int], [Int], ByteArray) Source #

writeForeign :: Stack 'UN -> Stack 'BX -> ByteArray -> IO (Stack 'UN, Stack 'BX) Source #

Lift ByteArray

Since: template-haskell-2.19.0.0

Instance details

Defined in Language.Haskell.TH.Syntax

Methods

lift :: Quote m => ByteArray -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => ByteArray -> Code m ByteArray #

type Item ByteArray 
Instance details

Defined in Data.Array.Byte

data MutableArray s a #

Mutable boxed arrays associated with a primitive state token.

Constructors

MutableArray 

Fields

Instances

Instances details
(Typeable s, Typeable a) => Data (MutableArray s a) 
Instance details

Defined in Data.Primitive.Array

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MutableArray s a -> c (MutableArray s a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (MutableArray s a) #

toConstr :: MutableArray s a -> Constr #

dataTypeOf :: MutableArray s a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (MutableArray s a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (MutableArray s a)) #

gmapT :: (forall b. Data b => b -> b) -> MutableArray s a -> MutableArray s a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MutableArray s a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MutableArray s a -> r #

gmapQ :: (forall d. Data d => d -> u) -> MutableArray s a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> MutableArray s a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) #

Eq (MutableArray s a) 
Instance details

Defined in Data.Primitive.Array

Methods

(==) :: MutableArray s a -> MutableArray s a -> Bool #

(/=) :: MutableArray s a -> MutableArray s a -> Bool #

ForeignConvention (MutableArray s RClosure) Source # 
Instance details

Defined in Unison.Runtime.Foreign.Function

data MutablePrimArray s 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.

Instances

Instances details
NFData (MutablePrimArray s a) 
Instance details

Defined in Data.Primitive.PrimArray

Methods

rnf :: MutablePrimArray s a -> () #

Eq (MutablePrimArray s a) 
Instance details

Defined in Data.Primitive.PrimArray

data PrimArray a #

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.

Constructors

PrimArray ByteArray# 

Instances

Instances details
Lift (PrimArray a :: Type) 
Instance details

Defined in Data.Primitive.PrimArray

Methods

lift :: Quote m => PrimArray a -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => PrimArray a -> Code m (PrimArray a) #

Monoid (PrimArray a)

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

Semigroup (PrimArray a)

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

Methods

(<>) :: PrimArray a -> PrimArray a -> PrimArray a #

sconcat :: NonEmpty (PrimArray a) -> PrimArray a #

stimes :: Integral b => b -> PrimArray a -> PrimArray a #

Prim a => IsList (PrimArray a)

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

Associated Types

type Item (PrimArray a) #

Methods

fromList :: [Item (PrimArray a)] -> PrimArray a #

fromListN :: Int -> [Item (PrimArray a)] -> PrimArray a #

toList :: PrimArray a -> [Item (PrimArray a)] #

(Show a, Prim a) => Show (PrimArray a)

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

NFData (PrimArray a) 
Instance details

Defined in Data.Primitive.PrimArray

Methods

rnf :: PrimArray a -> () #

(Eq a, Prim a) => Eq (PrimArray a)

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

Methods

(==) :: PrimArray a -> PrimArray a -> Bool #

(/=) :: PrimArray a -> PrimArray a -> Bool #

(Ord a, Prim a) => Ord (PrimArray a)

Lexicographic ordering. Subject to change between major versions.

Since: primitive-0.6.4.0

Instance details

Defined in Data.Primitive.PrimArray

type Item (PrimArray a) 
Instance details

Defined in Data.Primitive.PrimArray

type Item (PrimArray a) = a

fromList :: IsList l => [Item l] -> l #

The fromList function constructs the structure l from the given list of Item l

fromListN :: IsList l => Int -> [Item l] -> l #

The fromListN function takes the input list's length and potentially uses it to construct the structure l more efficiently compared to fromList. If the given number does not equal to the input list's length the behaviour of fromListN is not specified.

fromListN (length xs) xs == fromList xs

emptyArray :: Array a #

The empty Array.

newArray :: PrimMonad m => Int -> a -> m (MutableArray (PrimState m) a) #

Create a new mutable array of the specified size and initialise all elements with the given value.

Note: this function does not check if the input is non-negative.

newByteArray :: PrimMonad m => Int -> m (MutableByteArray (PrimState m)) #

Create a new mutable byte array of the specified size in bytes.

Note: this function does not check if the input is non-negative.

unsafeFreezeByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m ByteArray #

Convert a mutable byte array to an immutable one without copying. The array should not be modified after the conversion.

sizeofByteArray :: ByteArray -> Int #

Size of the byte array in bytes.

byteArrayFromListN :: Prim a => Int -> [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.

copyByteArrayToPtr #

Arguments

:: (PrimMonad m, Prim a) 
=> Ptr a

destination

-> ByteArray

source array

-> Int

offset into source array, interpreted as elements of type a

-> Int

number of elements to copy

-> m () 

Copy a slice of a byte array to an unmanaged pointer address. These must not overlap. The offset and length are given in elements, not in bytes.

Note: this function does not do bounds or overlap checking.

Since: primitive-0.7.1.0

newPinnedByteArray :: PrimMonad m => Int -> m (MutableByteArray (PrimState m)) #

Create a pinned byte array of the specified size in bytes. The garbage collector is guaranteed not to move it.

Note: this function does not check if the input is non-negative.

setByteArray #

Arguments

:: (Prim a, PrimMonad m) 
=> MutableByteArray (PrimState m)

array to fill

-> Int

offset into array

-> Int

number of values to fill

-> a

value to fill with

-> m () 

Fill a slice of a mutable byte array with a value. The offset and length are given in elements of type a rather than in bytes.

Note: this function does not do bounds checking.

sizeofArray :: Array a -> Int #

The number of elements in an immutable array.

sizeofMutableArray :: MutableArray s a -> Int #

The number of elements in a mutable array.

indexArray :: Array a -> Int -> a #

Read a value from the immutable array at the given index.

Note: this function does not do bounds checking.

indexArray## :: Array a -> Int -> (# a #) #

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.

indexArrayM :: Monad m => Array a -> Int -> m a #

Monadically read a value from the immutable array at the given index. This allows us to be strict in the array while remaining lazy in the read element which is very useful for collective operations. Suppose we want to copy an array. We could do something like this:

copy marr arr ... = do ...
                       writeArray marr i (indexArray arr i) ...
                       ...

But since the arrays are lazy, the calls to indexArray will not be evaluated. Rather, marr will be filled with thunks each of which would retain a reference to arr. This is definitely not what we want!

With indexArrayM, we can instead write

copy marr arr ... = do ...
                       x <- indexArrayM arr i
                       writeArray marr i x
                       ...

Now, indexing is executed immediately although the returned element is still not evaluated.

Note: this function does not do bounds checking.

freezeArray #

Arguments

:: PrimMonad m 
=> MutableArray (PrimState m) a

source

-> Int

offset

-> Int

length

-> m (Array a) 

Create an immutable copy of a slice of an array.

This operation makes a copy of the specified section, so it is safe to continue using the mutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

unsafeFreezeArray :: PrimMonad m => MutableArray (PrimState m) a -> m (Array a) #

Convert a mutable array to an immutable one without copying. The array should not be modified after the conversion.

thawArray #

Arguments

:: PrimMonad m 
=> Array a

source

-> Int

offset

-> Int

length

-> m (MutableArray (PrimState m) a) 

Create a mutable array from a slice of an immutable array.

This operation makes a copy of the specified slice, so it is safe to use the immutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

unsafeThawArray :: PrimMonad m => Array a -> m (MutableArray (PrimState m) a) #

Convert an immutable array to an mutable one without copying. The immutable array should not be used after the conversion.

sameMutableArray :: MutableArray s a -> MutableArray s a -> Bool #

Check whether the two arrays refer to the same memory block.

cloneArray #

Arguments

:: Array a

source array

-> Int

offset into destination array

-> Int

number of elements to copy

-> Array a 

Return a newly allocated Array with the specified subrange of the provided Array.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

runArray :: (forall s. ST s (MutableArray s a)) -> Array a #

Execute the monadic action and freeze the resulting array.

runArray m = runST $ m >>= unsafeFreezeArray

createArray :: Int -> a -> (forall s. MutableArray s a -> ST s ()) -> Array a #

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 emptyArray (rather than a new copy thereof).

createArray 0 _ _ = emptyArray
createArray n x f = runArray $ do
  mary <- newArray n x
  f mary
  pure mary

traverseArrayP :: PrimMonad m => (a -> m b) -> Array a -> m (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.

mapArray' :: (a -> b) -> Array a -> Array b #

Strict map over the elements of the array.

arrayFromListN :: Int -> [a] -> Array a #

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.

arrayFromList :: [a] -> Array a #

Create an array from a list.

newAlignedPinnedByteArray #

Arguments

:: PrimMonad m 
=> Int

size

-> Int

alignment

-> m (MutableByteArray (PrimState m)) 

Create a pinned byte array of the specified size in bytes and with the given alignment. The garbage collector is guaranteed not to move it.

Note: this function does not check if the input is non-negative.

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 #

Yield a pointer to the array's data. This operation is only safe on pinned byte arrays allocated by newPinnedByteArray or newAlignedPinnedByteArray.

sameMutableByteArray :: MutableByteArray s -> MutableByteArray s -> Bool #

Check if the two arrays refer to the same memory block.

resizeMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m (MutableByteArray (PrimState m)) #

Resize a mutable byte array. The new size is given in bytes.

This will either resize the array in-place or, if not possible, allocate the contents into a new, unpinned array and copy the original array's contents.

To avoid undefined behaviour, the original MutableByteArray shall not be accessed anymore after a resizeMutableByteArray has been performed. Moreover, no reference to the old one should be kept in order to allow garbage collection of the original MutableByteArray in case a new MutableByteArray had to be allocated.

Since: primitive-0.6.4.0

getSizeofMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m Int #

Get the size of a byte array in bytes. Unlike sizeofMutableByteArray, this function ensures sequencing in the presence of resizing.

freezeByteArray #

Arguments

:: PrimMonad m 
=> MutableByteArray (PrimState m)

source

-> Int

offset in bytes

-> Int

length in bytes

-> m ByteArray 

Create an immutable copy of a slice of a byte array. The offset and length are given in bytes.

This operation makes a copy of the specified section, so it is safe to continue using the mutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

thawByteArray #

Arguments

:: PrimMonad m 
=> ByteArray

source

-> Int

offset in bytes

-> Int

length in bytes

-> m (MutableByteArray (PrimState m)) 

Create a mutable byte array from a slice of an immutable byte array. The offset and length are given in bytes.

This operation makes a copy of the specified slice, so it is safe to use the immutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

Since: primitive-0.7.2.0

unsafeThawByteArray :: PrimMonad m => ByteArray -> m (MutableByteArray (PrimState m)) #

Convert an immutable byte array to a mutable one without copying. The original array should not be used after the conversion.

sizeofMutableByteArray :: MutableByteArray s -> 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.

shrinkMutableByteArray #

Arguments

:: PrimMonad m 
=> MutableByteArray (PrimState m) 
-> Int

new size

-> m () 

Shrink a mutable byte array. The new size is given in bytes. It must be smaller than the old size. The array will be resized in place.

Since: primitive-0.7.1.0

isByteArrayPinned :: ByteArray -> 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.

Caution: This function is only available when compiling with GHC 8.2 or newer.

Since: primitive-0.6.4.0

isMutableByteArrayPinned :: MutableByteArray s -> Bool #

Check whether or not the mutable byte array is pinned.

Caution: This function is only available when compiling with GHC 8.2 or newer.

Since: primitive-0.6.4.0

foldrByteArray :: Prim a => (a -> b -> b) -> b -> ByteArray -> b #

Right-fold over the elements of a ByteArray.

byteArrayFromList :: Prim a => [a] -> ByteArray #

Create a ByteArray from a list.

byteArrayFromList xs = byteArrayFromListN (length xs) xs

copyPtrToMutableByteArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutableByteArray (PrimState m)

destination array

-> Int

destination offset given in elements of type a

-> Ptr a

source pointer

-> Int

number of elements

-> m () 

Copy from an unmanaged pointer address to a byte array. These must not overlap. The offset and length are given in elements, not in bytes.

Note: this function does not do bounds or overlap checking.

copyMutableByteArrayToPtr #

Arguments

:: (PrimMonad m, Prim a) 
=> Ptr a

destination

-> MutableByteArray (PrimState m)

source array

-> Int

offset into source array, interpreted as elements of type a

-> Int

number of elements to copy

-> m () 

Copy a slice of a mutable byte array to an unmanaged pointer address. These must not overlap. The offset and length are given in elements, not in bytes.

Note: this function does not do bounds or overlap checking.

Since: primitive-0.7.1.0

copyByteArrayToAddr #

Arguments

:: PrimMonad m 
=> Ptr Word8

destination

-> ByteArray

source array

-> Int

offset into source array

-> Int

number of bytes to copy

-> m () 

Copy a slice of a byte array to an unmanaged address. These must not overlap.

Note: This function is just copyByteArrayToPtr where a is Word8.

Since: primitive-0.6.4.0

copyMutableByteArrayToAddr #

Arguments

:: PrimMonad m 
=> Ptr Word8

destination

-> MutableByteArray (PrimState m)

source array

-> Int

offset into source array

-> Int

number of bytes to copy

-> m () 

Copy a slice of a mutable byte array to an unmanaged address. These must not overlap.

Note: This function is just copyMutableByteArrayToPtr where a is Word8.

Since: primitive-0.6.4.0

fillByteArray #

Arguments

:: PrimMonad m 
=> MutableByteArray (PrimState m)

array to fill

-> Int

offset into array

-> Int

number of bytes to fill

-> Word8

byte to fill with

-> m () 

Fill a slice of a mutable byte array with a byte.

Note: this function does not do bounds checking.

compareByteArrays #

Arguments

:: ByteArray

array A

-> Int

offset A, given in bytes

-> ByteArray

array B

-> Int

offset B, given in bytes

-> Int

length of the slice, given in bytes

-> Ordering 

Lexicographic comparison of equal-length slices into two byte arrays. This wraps the compareByteArrays# primop, which wraps memcmp.

cloneByteArray #

Arguments

:: ByteArray

source array

-> Int

offset into destination array

-> Int

number of bytes to copy

-> ByteArray 

Return a newly allocated array with the specified subrange of the provided array. The provided array should contain the full subrange specified by the two Ints, but this is not checked.

cloneMutableByteArray #

Arguments

:: PrimMonad m 
=> MutableByteArray (PrimState m)

source array

-> Int

offset into destination array

-> Int

number of bytes to copy

-> m (MutableByteArray (PrimState m)) 

Return a newly allocated mutable array with the specified subrange of the provided mutable array. The provided mutable array should contain the full subrange specified by the two Ints, but this is not checked.

runByteArray :: (forall s. ST s (MutableByteArray s)) -> ByteArray #

Execute the monadic action and freeze the resulting array.

runByteArray m = runST $ m >>= unsafeFreezeByteArray

readCharArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m Char #

Read an 8-bit element from the byte array, interpreting it as a Latin-1-encoded character. The offset is given in bytes.

Note: this function does not do bounds checking.

writeCharArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> Char -> m () #

Write a character to the byte array, encoding it with Latin-1 as a single byte. Behavior is undefined for codepoints outside of the ASCII and Latin-1 blocks. The offset is given in bytes.

Note: this function does not do bounds checking.

indexCharArray :: ByteArray -> Int -> Char #

Read an 8-bit element from the byte array, interpreting it as a Latin-1-encoded character. The offset is given in bytes.

Note: this function does not do bounds checking.

primArrayFromList :: Prim a => [a] -> PrimArray a #

Create a PrimArray from a list.

primArrayFromList vs = primArrayFromListN (length vs) vs

primArrayFromListN :: Prim a => Int -> [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.

primArrayToList :: Prim a => PrimArray a -> [a] #

Convert a PrimArray to a list.

newPrimArray :: (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) #

Create a new mutable primitive array of the given length. The underlying memory is left uninitialized.

Note: this function does not check if the input is non-negative.

resizeMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a 
-> Int

new size

-> m (MutablePrimArray (PrimState m) a) 

Resize a mutable primitive array. The new size is given in elements.

This will either resize the array in-place or, if not possible, allocate the contents into a new, unpinned array and copy the original array's contents.

To avoid undefined behaviour, the original MutablePrimArray shall not be accessed anymore after a resizeMutablePrimArray has been performed. Moreover, no reference to the old one should be kept in order to allow garbage collection of the original MutablePrimArray in case a new MutablePrimArray had to be allocated.

shrinkMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a 
-> Int

new size

-> m () 

Shrink a mutable primitive array. The new size is given in elements. It must be smaller than the old size. The array will be resized in place.

copyMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

destination array

-> Int

offset into destination array

-> MutablePrimArray (PrimState m) a

source array

-> Int

offset into source array

-> Int

number of elements to copy

-> m () 

Copy part of a mutable array into another mutable array. In the case that the destination and source arrays are the same, the regions may overlap.

Note: this function does not do bounds or overlap checking.

copyPrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

destination array

-> Int

offset into destination array

-> PrimArray a

source array

-> Int

offset into source array

-> Int

number of elements to copy

-> m () 

Copy part of an array into another mutable array.

Note: this function does not do bounds or overlap checking.

copyPrimArrayToPtr #

Arguments

:: (PrimMonad m, Prim a) 
=> Ptr a

destination pointer

-> PrimArray a

source array

-> Int

offset into source array

-> Int

number of elements to copy

-> m () 

Copy a slice of an immutable primitive array to a pointer. The offset and length are given in elements of type a. This function assumes that the Prim instance of a agrees with the Storable instance.

Note: this function does not do bounds or overlap checking.

copyMutablePrimArrayToPtr #

Arguments

:: (PrimMonad m, Prim a) 
=> Ptr a

destination pointer

-> MutablePrimArray (PrimState m) a

source array

-> Int

offset into source array

-> Int

number of elements to copy

-> m () 

Copy a slice of a mutable primitive array to a pointer. The offset and length are given in elements of type a. This function assumes that the Prim instance of a agrees with the Storable instance.

Note: this function does not do bounds or overlap checking.

copyPtrToMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

destination array

-> Int

destination offset

-> Ptr a

source pointer

-> Int

number of elements

-> m () 

Copy from a pointer to a mutable primitive array. The offset and length are given in elements of type a. This function assumes that the Prim instance of a agrees with the Storable instance.

Note: this function does not do bounds or overlap checking.

setPrimArray #

Arguments

:: (Prim a, PrimMonad m) 
=> MutablePrimArray (PrimState m) a

array to fill

-> Int

offset into array

-> Int

number of values to fill

-> a

value to fill with

-> m () 

Fill a slice of a mutable primitive array with a value.

Note: this function does not do bounds checking.

getSizeofMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

array

-> m Int 

Get the size of a mutable primitive array in elements. Unlike sizeofMutablePrimArray, this function ensures sequencing in the presence of resizing.

sizeofMutablePrimArray :: forall s a. Prim a => MutablePrimArray s a -> 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.

sameMutablePrimArray :: MutablePrimArray s a -> MutablePrimArray s a -> Bool #

Check if the two arrays refer to the same memory block.

freezePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

source

-> Int

offset in elements

-> Int

length in elements

-> m (PrimArray a) 

Create an immutable copy of a slice of a primitive array. The offset and length are given in elements.

This operation makes a copy of the specified section, so it is safe to continue using the mutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

thawPrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> PrimArray a

source

-> Int

offset in elements

-> Int

length in elements

-> m (MutablePrimArray (PrimState m) a) 

Create a mutable primitive array from a slice of an immutable primitive array. The offset and length are given in elements.

This operation makes a copy of the specified slice, so it is safe to use the immutable array afterward.

Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.

Since: primitive-0.7.2.0

unsafeFreezePrimArray :: PrimMonad m => MutablePrimArray (PrimState m) a -> m (PrimArray a) #

Convert a mutable primitive array to an immutable one without copying. The array should not be modified after the conversion.

unsafeThawPrimArray :: PrimMonad m => PrimArray a -> m (MutablePrimArray (PrimState m) a) #

Convert an immutable array to a mutable one without copying. The original array should not be used after the conversion.

sizeofPrimArray :: Prim a => PrimArray a -> Int #

Get the size, in elements, of the primitive array.

isPrimArrayPinned :: PrimArray a -> Bool #

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.

Since: primitive-0.7.1.0

isMutablePrimArrayPinned :: MutablePrimArray s 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.

Since: primitive-0.7.1.0

foldrPrimArray :: Prim a => (a -> b -> b) -> b -> PrimArray a -> b #

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.

foldlPrimArray :: Prim a => (b -> a -> 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.

foldlPrimArrayM' :: (Prim a, Monad m) => (b -> a -> m b) -> b -> PrimArray a -> m b #

Strict left-associated fold over the elements of a PrimArray.

traversePrimArrayP :: (PrimMonad m, Prim a, Prim b) => (a -> m b) -> PrimArray a -> m (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.

filterPrimArrayP :: (PrimMonad m, Prim a) => (a -> m Bool) -> PrimArray a -> m (PrimArray a) #

Filter the primitive array, keeping the elements for which the monadic predicate evaluates to true.

mapMaybePrimArrayP :: (PrimMonad m, Prim a, Prim b) => (a -> m (Maybe b)) -> PrimArray a -> m (PrimArray b) #

Map over the primitive array, keeping the elements for which the monadic predicate provides a Just.

generatePrimArrayP #

Arguments

:: (PrimMonad m, Prim a) 
=> Int

length

-> (Int -> m a)

generator

-> m (PrimArray a) 

Generate a primitive array by evaluating the monadic generator function at each index.

replicatePrimArrayP :: (PrimMonad m, Prim a) => Int -> m a -> m (PrimArray a) #

Execute the monadic action the given number of times and store the results in a primitive array.

mapPrimArray :: (Prim a, Prim b) => (a -> b) -> PrimArray a -> PrimArray b #

Map over the elements of a primitive array.

imapPrimArray :: (Prim a, Prim b) => (Int -> a -> b) -> PrimArray a -> PrimArray b #

Indexed map over the elements of a primitive array.

filterPrimArray :: Prim a => (a -> Bool) -> PrimArray a -> PrimArray a #

Filter elements of a primitive array according to a predicate.

filterPrimArrayA #

Arguments

:: (Applicative f, Prim a) 
=> (a -> f Bool)

mapping function

-> PrimArray a

primitive array

-> f (PrimArray a) 

Filter the primitive array, keeping the elements for which the monadic predicate evaluates true.

mapMaybePrimArrayA #

Arguments

:: (Applicative f, Prim a, Prim b) 
=> (a -> f (Maybe b))

mapping function

-> PrimArray a

primitive array

-> f (PrimArray b) 

Map over the primitive array, keeping the elements for which the applicative predicate provides a Just.

mapMaybePrimArray :: (Prim a, Prim b) => (a -> Maybe b) -> PrimArray a -> PrimArray b #

Map over a primitive array, optionally discarding some elements. This has the same behavior as Data.Maybe.mapMaybe.

traversePrimArray #

Arguments

:: (Applicative f, Prim a, Prim b) 
=> (a -> f b)

mapping function

-> PrimArray a

primitive array

-> f (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.

itraversePrimArray :: (Applicative f, Prim a, Prim b) => (Int -> a -> f b) -> PrimArray a -> f (PrimArray b) #

Traverse a primitive array with the index of each element.

itraversePrimArrayP :: (Prim a, Prim b, PrimMonad m) => (Int -> 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.

generatePrimArray #

Arguments

:: Prim a 
=> Int

length

-> (Int -> a)

element from index

-> PrimArray a 

Generate a primitive array.

replicatePrimArray #

Arguments

:: Prim a 
=> Int

length

-> a

element

-> PrimArray a 

Create a primitive array by copying the element the given number of times.

generatePrimArrayA #

Arguments

:: (Applicative f, Prim a) 
=> Int

length

-> (Int -> f a)

element from index

-> f (PrimArray a) 

Generate a primitive array by evaluating the applicative generator function at each index.

replicatePrimArrayA #

Arguments

:: (Applicative f, Prim a) 
=> Int

length

-> f a

applicative element producer

-> f (PrimArray a) 

Execute the applicative action the given number of times and store the results in a PrimArray.

traversePrimArray_ :: (Applicative f, Prim a) => (a -> f b) -> PrimArray a -> f () #

Traverse the primitive array, 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 () #

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.

newPinnedPrimArray :: (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) #

Create a pinned primitive array of the specified size (in elements). The garbage collector is guaranteed not to move it.

Since: primitive-0.7.1.0

newAlignedPinnedPrimArray :: (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) #

Create a pinned primitive array of the specified size (in elements) and with the alignment given by its Prim instance. The garbage collector is guaranteed not to move it.

Since: primitive-0.7.0.0

primArrayContents :: PrimArray a -> Ptr a #

Yield a pointer to the array's data. This operation is only safe on pinned prim arrays allocated by newPinnedByteArray or newAlignedPinnedByteArray.

Since: primitive-0.7.1.0

mutablePrimArrayContents :: MutablePrimArray s 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.

Since: primitive-0.7.1.0

clonePrimArray #

Arguments

:: Prim a 
=> PrimArray a

source array

-> Int

offset into destination array

-> Int

number of elements to copy

-> PrimArray a 

Return a newly allocated array with the specified subrange of the provided array. The provided array should contain the full subrange specified by the two Ints, but this is not checked.

cloneMutablePrimArray #

Arguments

:: (PrimMonad m, Prim a) 
=> MutablePrimArray (PrimState m) a

source array

-> Int

offset into destination array

-> Int

number of elements to copy

-> m (MutablePrimArray (PrimState m) a) 

Return a newly allocated mutable array with the specified subrange of the provided mutable array. The provided mutable array should contain the full subrange specified by the two Ints, but this is not checked.

runPrimArray :: (forall s. ST s (MutablePrimArray s a)) -> PrimArray a #

Execute the monadic action and freeze the resulting array.

runPrimArray m = runST $ m >>= unsafeFreezePrimArray

readArray :: CheckCtx => PrimMonad m => MutableArray (PrimState m) a -> Int -> m a Source #

writeArray :: CheckCtx => PrimMonad m => MutableArray (PrimState m) a -> Int -> a -> m () Source #

copyArray :: CheckCtx => PrimMonad m => MutableArray (PrimState m) a -> Int -> Array a -> Int -> Int -> m () Source #

copyMutableArray :: CheckCtx => PrimMonad m => MutableArray (PrimState m) a -> Int -> MutableArray (PrimState m) a -> Int -> Int -> m () Source #

cloneMutableArray :: CheckCtx => PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> m (MutableArray (PrimState m) a) Source #

readByteArray :: forall a m. CheckCtx => PrimMonad m => Prim a => MutableByteArray (PrimState m) -> Int -> m a Source #

writeByteArray :: forall a m. CheckCtx => PrimMonad m => Prim a => MutableByteArray (PrimState m) -> Int -> a -> m () Source #

indexByteArray :: forall a. CheckCtx => Prim a => ByteArray -> Int -> a Source #

copyByteArray :: CheckCtx => PrimMonad m => MutableByteArray (PrimState m) -> Int -> ByteArray -> Int -> Int -> m () Source #

readPrimArray :: CheckCtx => PrimMonad m => Prim a => MutablePrimArray (PrimState m) a -> Int -> m a Source #

writePrimArray :: CheckCtx => PrimMonad m => Prim a => MutablePrimArray (PrimState m) a -> Int -> a -> m () Source #

indexPrimArray :: CheckCtx => Prim a => PrimArray a -> Int -> a Source #