Copyright | (c) Roman Leshchinskiy 2009-2012 |
---|---|
License | BSD-style |
Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Primitive arrays of boxed values.
- data Array a = Array {}
- data MutableArray s a = MutableArray {
- marray# :: MutableArray# s a
- newArray :: PrimMonad m => Int -> a -> m (MutableArray (PrimState m) a)
- readArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> m a
- writeArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> a -> m ()
- indexArray :: Array a -> Int -> a
- indexArrayM :: Monad m => Array a -> Int -> m a
- freezeArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> m (Array a)
- thawArray :: PrimMonad m => Array a -> Int -> Int -> m (MutableArray (PrimState m) a)
- unsafeFreezeArray :: PrimMonad m => MutableArray (PrimState m) a -> m (Array a)
- unsafeThawArray :: PrimMonad m => Array a -> m (MutableArray (PrimState m) a)
- sameMutableArray :: MutableArray s a -> MutableArray s a -> Bool
- copyArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Array a -> Int -> Int -> m ()
- copyMutableArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> MutableArray (PrimState m) a -> Int -> Int -> m ()
- cloneArray :: Array a -> Int -> Int -> Array a
- cloneMutableArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> m (MutableArray (PrimState m) a)
- sizeofArray :: Array a -> Int
- sizeofMutableArray :: MutableArray s a -> Int
- fromListN :: IsList l => Int -> [Item l] -> l
- fromList :: IsList l => [Item l] -> l
Documentation
Boxed arrays
Monad Array Source # | |
Functor Array Source # | |
MonadFix Array Source # | |
Applicative Array Source # | |
Foldable Array Source # | |
Traversable Array Source # | |
MonadZip Array Source # | |
Alternative Array Source # | |
MonadPlus Array Source # | |
IsList (Array a) Source # | |
Eq a => Eq (Array a) Source # | |
Data a => Data (Array a) Source # | |
Ord a => Ord (Array a) Source # | |
Read a => Read (Array a) Source # | |
Show a => Show (Array a) Source # | |
Semigroup (Array a) Source # | |
Monoid (Array a) Source # | |
PrimUnlifted (Array a) Source # | |
type Item (Array a) Source # | |
data MutableArray s a Source #
Mutable boxed arrays associated with a primitive state token.
MutableArray | |
|
Eq (MutableArray s a) Source # | |
(Typeable * s, Typeable * a) => Data (MutableArray s a) Source # | |
PrimUnlifted (MutableArray s a) Source # | |
newArray :: PrimMonad m => Int -> a -> m (MutableArray (PrimState m) a) Source #
Create a new mutable array of the specified size and initialise all elements with the given value.
readArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> m a Source #
Read a value from the array at the given index.
writeArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> a -> m () Source #
Write a value to the array at the given index.
indexArray :: Array a -> Int -> a Source #
Read a value from the immutable array at the given index.
indexArrayM :: Monad m => Array a -> Int -> m a Source #
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 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.
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.
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.
unsafeFreezeArray :: PrimMonad m => MutableArray (PrimState m) a -> m (Array a) Source #
Convert a mutable array to an immutable one without copying. The array should not be modified after the conversion.
unsafeThawArray :: PrimMonad m => Array a -> m (MutableArray (PrimState m) a) Source #
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 Source #
Check whether the two arrays refer to the same memory block.
:: PrimMonad m | |
=> MutableArray (PrimState m) a | destination array |
-> Int | offset into destination array |
-> Array a | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of an immutable array to a mutable array.
:: PrimMonad m | |
=> MutableArray (PrimState m) a | destination array |
-> Int | offset into destination array |
-> MutableArray (PrimState m) a | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of a mutable array to another array. The two arrays may not be the same.
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.
:: PrimMonad m | |
=> MutableArray (PrimState m) a | source array |
-> Int | offset into destination array |
-> Int | number of elements to copy |
-> m (MutableArray (PrimState m) a) |
Return a newly allocated MutableArray. with the specified subrange of the provided MutableArray. The provided MutableArray should contain the full subrange specified by the two Ints, but this is not checked.
sizeofArray :: Array a -> Int Source #
sizeofMutableArray :: MutableArray s a -> Int Source #
fromListN :: IsList l => Int -> [Item l] -> l #
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.