-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Wrappers for primitive operations -- -- This package provides wrappers for primitive array operations from -- GHC.Prim. -- -- Changes in version 0.4 -- --
-- copy marr arr ... = do ... -- writeArray marr i (indexArray arr i) ... -- ... ---- -- But since primitive 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. indexArrayM :: Monad m => Array a -> Int -> m a -- | Convert a mutable array to an immutable one without copying. The array -- should not be modified after the conversion. unsafeFreezeArray :: 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 -- | Copy a slice of an immutable array to a mutable array. copyArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Array a -> Int -> Int -> m () -- | Copy a slice of a mutable array to another array. The two arrays may -- not be the same. copyMutableArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> MutableArray (PrimState m) a -> Int -> Int -> m () instance Typeable1 Array instance Typeable2 MutableArray instance (Typeable s, Typeable a) => Data (MutableArray s a) instance Typeable a => Data (Array a) -- | Primitive operations on ByteArrays 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# :: # data MutableByteArray# a :: * :: * -> # -- | Create a new mutable byte array of the specified size. newByteArray :: PrimMonad m => Int -> m (MutableByteArray (PrimState m)) -- | Create a pinned byte array of the specified size. The garbage -- collector is guaranteed not to move it. newPinnedByteArray :: PrimMonad m => Int -> m (MutableByteArray (PrimState m)) -- | Create a pinned byte array of the specified size and with the -- give alignment. The garbage collector is guaranteed not to move it. newAlignedPinnedByteArray :: PrimMonad m => Int -> Int -> m (MutableByteArray (PrimState m)) -- | Read a primitive value from the byte array. The offset is given in -- elements of type a rather than in bytes. readByteArray :: (Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m a -- | Write a primitive value to the byte array. The offset is given in -- elements of type a rather than in bytes. writeByteArray :: (Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> a -> m () -- | Read a primitive value from the byte array. The offset is given in -- elements of type a rather than in bytes. indexByteArray :: Prim a => ByteArray -> Int -> a -- | Convert a mutable byte array to an immutable one without copying. The -- array should not be modified after the conversion. unsafeFreezeByteArray :: 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)) -- | Size of the byte array. sizeofByteArray :: ByteArray -> Int -- | Size of the mutable byte array. sizeofMutableByteArray :: MutableByteArray s -> Int -- | Check if the two arrays refer to the same memory block. sameMutableByteArray :: MutableByteArray s -> 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 -> Addr -- | 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 -> Addr -- | Copy a slice of an immutable byte array to a mutable byte array. copyByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> ByteArray -> Int -> Int -> m () -- | Copy a slice of a mutable byte array into another array. The two -- slices may not overlap. copyMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () -- | Copy a slice of a mutable byte array into another, potentially -- overlapping array. moveByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () -- | Fill a slice of a mutable byte array with a value. fillByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> Int -> Word8 -> m () memcpyByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () memcpyByteArray' :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> ByteArray -> Int -> Int -> m () memmoveByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m () memsetByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> Word8 -> Int -> m () instance Typeable ByteArray instance Typeable1 MutableByteArray instance Typeable s => Data (MutableByteArray s) instance Data ByteArray -- | Primitive operations on machine addresses module Data.Primitive.Addr -- | A machine address data Addr Addr :: Addr# -> Addr -- | The null address nullAddr :: Addr -- | Offset an address by the given number of bytes plusAddr :: Addr -> Int -> Addr -- | Distance in bytes between two addresses. The result is only valid if -- the difference fits in an Int. minusAddr :: Addr -> Addr -> Int -- | The remainder of the address and the integer. remAddr :: Addr -> Int -> Int -- | Read a value from a memory position given by an address and an offset. -- The memory block the address refers to must be immutable. The offset -- is in elements of type a rather than in bytes. indexOffAddr :: Prim a => Addr -> Int -> a -- | Read a value from a memory position given by an address and an offset. -- The offset is in elements of type a rather than in bytes. readOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> m a -- | Write a value to a memory position given by an address and an offset. -- The offset is in elements of type a rather than in bytes. writeOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m () -- | Copy the given number of bytes from the second Addr to the -- first. The areas may not overlap. copyAddr :: PrimMonad m => Addr -> Addr -> Int -> m () -- | Copy the given number of bytes from the second Addr to the -- first. The areas may overlap. moveAddr :: PrimMonad m => Addr -> Addr -> Int -> m () memcpyAddr :: PrimMonad m => Addr -> Addr -> Int -> m () -- | Reexports all primitive operations module Data.Primitive -- | Size of values of type a. The argument is not used. sizeOf :: Prim a => a -> Int -- | Alignment of values of type a. The argument is not used. alignment :: Prim a => a -> Int