Safe Haskell | None |
---|---|
Language | Haskell2010 |
The contiguous typeclass parameterises over a contiguous array type. This allows us to have a common API to a number of contiguous array types and their mutable counterparts.
Synopsis
- size :: (Contiguous arr, Element arr b) => arr b -> Int
- sizeMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int
- null :: Contiguous arr => arr b -> Bool
- index :: (Contiguous arr, Element arr b) => arr b -> Int -> b
- index# :: (Contiguous arr, Element arr b) => arr b -> Int -> (#b#)
- read :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m b
- indexM :: (Contiguous arr, Element arr b, Monad m) => arr b -> Int -> m b
- empty :: Contiguous arr => arr a
- new :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b)
- singleton :: (Contiguous arr, Element arr a) => a -> arr a
- doubleton :: (Contiguous arr, Element arr a) => a -> a -> arr a
- tripleton :: (Contiguous arr, Element arr a) => a -> a -> a -> arr a
- replicate :: (Contiguous arr, Element arr a) => Int -> a -> arr a
- replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b)
- generate :: (Contiguous arr, Element arr a) => Int -> (Int -> a) -> arr a
- generateM :: (Contiguous arr, Element arr a, Monad m) => Int -> (Int -> m a) -> m (arr a)
- generateMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> a) -> m (Mutable arr (PrimState m) a)
- iterateN :: (Contiguous arr, Element arr a) => Int -> (a -> a) -> a -> arr a
- iterateMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> a) -> a -> m (Mutable arr (PrimState m) a)
- write :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m ()
- replicateMutableM :: (PrimMonad m, Contiguous arr, Element arr a) => Int -> m a -> m (Mutable arr (PrimState m) a)
- generateMutableM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> m a) -> m (Mutable arr (PrimState m) a)
- iterateMutableNM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> m a) -> a -> m (Mutable arr (PrimState m) a)
- create :: (Contiguous arr, Element arr a) => (forall s. ST s (Mutable arr s a)) -> arr a
- createT :: (Contiguous arr, Element arr a, Traversable f) => (forall s. ST s (f (Mutable arr s a))) -> f (arr a)
- unfoldr :: (Contiguous arr, Element arr a) => (b -> Maybe (a, b)) -> b -> arr a
- unfoldrN :: (Contiguous arr, Element arr a) => Int -> (b -> Maybe (a, b)) -> b -> arr a
- unfoldrMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (b -> Maybe (a, b)) -> b -> m (Mutable arr (PrimState m) a)
- enumFromN :: (Contiguous arr, Element arr a, Enum a) => a -> Int -> arr a
- enumFromMutableN :: (Contiguous arr, Element arr a, PrimMonad m, Enum a) => a -> Int -> m (Mutable arr (PrimState m) a)
- append :: (Contiguous arr, Element arr a) => arr a -> arr a -> arr a
- reverse :: (Contiguous arr, Element arr a) => arr a -> arr a
- reverseMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m ()
- reverseSlice :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> Int -> Int -> m ()
- resize :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m (Mutable arr (PrimState m) b)
- map :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c
- map' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c
- mapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- imap :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c
- imap' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c
- imapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m ()
- imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m ()
- modify :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- modify' :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m ()
- mapMaybe :: forall arr1 arr2 a b. (Contiguous arr1, Element arr1 a, Contiguous arr2, Element arr2 b) => (a -> Maybe b) -> arr1 a -> arr2 b
- zip :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 (a, b)) => arr1 a -> arr2 b -> arr3 (a, b)
- zipWith :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 c) => (a -> b -> c) -> arr1 a -> arr2 b -> arr3 c
- swap :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> Int -> Int -> m ()
- filter :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> arr a
- ifilter :: (Contiguous arr, Element arr a) => (Int -> a -> Bool) -> arr a -> arr a
- catMaybes :: (Contiguous arr, Element arr a, Element arr (Maybe a)) => arr (Maybe a) -> arr a
- lefts :: forall arr a b. (Contiguous arr, Element arr a, Element arr (Either a b)) => arr (Either a b) -> arr a
- rights :: forall arr a b. (Contiguous arr, Element arr b, Element arr (Either a b)) => arr (Either a b) -> arr b
- partitionEithers :: forall arr a b. (Contiguous arr, Element arr a, Element arr b, Element arr (Either a b)) => arr (Either a b) -> (arr a, arr b)
- find :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> Maybe a
- elem :: (Contiguous arr, Element arr a, Eq a) => a -> arr a -> Bool
- maximum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a
- minimum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a
- maximumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a
- minimumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a
- equals :: (Contiguous arr, Element arr b, Eq b) => arr b -> arr b -> Bool
- equalsMutable :: Contiguous arr => Mutable arr s a -> Mutable arr s a -> Bool
- same :: Contiguous arr => arr a -> arr a -> Bool
- foldl :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b
- foldl' :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b
- foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b
- foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b
- foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- foldMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m
- ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b
- ifoldr' :: (Contiguous arr, Element arr a) => (Int -> a -> b -> b) -> b -> arr a -> b
- ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m
- ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m
- foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b
- asum :: (Contiguous arr, Element arr (f a), Alternative f) => arr (f a) -> f a
- traverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (a -> f b) -> arr1 a -> f (arr2 b)
- traverse_ :: (Contiguous arr, Element arr a, Applicative f) => (a -> f b) -> arr a -> f ()
- itraverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (Int -> a -> f b) -> arr1 a -> f (arr2 b)
- itraverse_ :: (Contiguous arr, Element arr a, Applicative f) => (Int -> a -> f b) -> arr a -> f ()
- traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> m b) -> arr1 a -> m (arr2 b)
- mapM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => (a -> m b) -> arr1 a -> m (arr2 b)
- forM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => arr1 a -> (a -> m b) -> m (arr2 b)
- mapM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f ()
- forM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f ()
- for :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => arr1 a -> (a -> f b) -> f (arr2 b)
- for_ :: (Contiguous arr, Element arr a, Applicative f) => arr a -> (a -> f b) -> f ()
- sequence :: (Contiguous arr1, Contiguous arr2, Element arr1 (f a), Element arr2 a, Applicative f) => arr1 (f a) -> f (arr2 a)
- sequence_ :: (Contiguous arr, Element arr (f a), Applicative f) => arr (f a) -> f ()
- (<$) :: (Contiguous arr1, Contiguous arr2, Element arr1 b, Element arr2 a) => a -> arr1 b -> arr2 a
- ap :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 (a -> b), Element arr2 a, Element arr3 b) => arr1 (a -> b) -> arr2 a -> arr3 b
- scanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b
- scanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b
- iscanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b
- iscanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b
- prescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b
- prescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b
- iprescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b
- iprescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b
- fromList :: (Contiguous arr, Element arr a) => [a] -> arr a
- fromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- fromListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => [a] -> m (Mutable arr (PrimState m) a)
- fromListMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a)
- unsafeFromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- unsafeFromListReverseN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a
- unsafeFromListReverseMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a)
- toList :: (Contiguous arr, Element arr a) => arr a -> [a]
- toListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m [a]
- convert :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 b) => arr1 b -> arr2 b
- lift :: Contiguous arr => ArrayArray# -> arr b
- unlift :: Contiguous arr => arr b -> ArrayArray#
- clone :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> arr b
- cloneMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b)
- copy :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()
- copyMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()
- freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)
- thaw :: (Contiguous arr, PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)
- unsafeFreeze :: (Contiguous arr, PrimMonad m) => Mutable arr (PrimState m) b -> m (arr b)
- liftHashWithSalt :: (Contiguous arr, Element arr a) => (Int -> a -> Int) -> Int -> arr a -> Int
- rnf :: (Contiguous arr, NFData a, Element arr a) => arr a -> ()
- class Contiguous (arr :: Type -> Type) where
- class Always a
- data Array a
- data MutableArray s a
- data SmallArray a
- data SmallMutableArray s a
- data PrimArray a
- data MutablePrimArray s a
- data UnliftedArray a
- data MutableUnliftedArray s a
Accessors
Length Information
sizeMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int Source #
The size of the mutable array
null :: Contiguous arr => arr b -> Bool Source #
Test whether the array is empty.
Indexing
index :: (Contiguous arr, Element arr b) => arr b -> Int -> b Source #
Index into an array at the given index.
index# :: (Contiguous arr, Element arr b) => arr b -> Int -> (#b#) Source #
Index into an array at the given index, yielding an unboxed one-tuple of the element.
read :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m b Source #
Read a mutable array at the given index.
Monadic indexing
indexM :: (Contiguous arr, Element arr b, Monad m) => arr b -> Int -> m b Source #
Indexing in a monad.
The monad allows operations to be strict in the array when necessary. Suppose array copying is implemented like this:
copy mv v = ... write mv i (v ! i) ...
For lazy arrays, v ! i
would not be not be evaluated,
which means that mv
would unnecessarily retain a reference
to v
in each element written.
With indexM
, copying can be implemented like this instead:
copy mv v = ... do x <- indexM v i write mv i x
Here, no references to v
are retained because indexing
(but not the elements) is evaluated eagerly.
Construction
Initialisation
empty :: Contiguous arr => arr a Source #
The empty array.
new :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b) Source #
Allocate a new mutable array of the given size.
singleton :: (Contiguous arr, Element arr a) => a -> arr a Source #
Create a singleton array.
doubleton :: (Contiguous arr, Element arr a) => a -> a -> arr a Source #
Create a doubleton array.
tripleton :: (Contiguous arr, Element arr a) => a -> a -> a -> arr a Source #
Create a tripleton array.
replicate :: (Contiguous arr, Element arr a) => Int -> a -> arr a Source #
is an array of length replicate
n xn
with x
the value of every element.
replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b) Source #
is a mutable array of length replicateMutable
n xn
with x
the value of every element.
generate :: (Contiguous arr, Element arr a) => Int -> (Int -> a) -> arr a Source #
Construct an array of the given length by applying the function to each index.
generateM :: (Contiguous arr, Element arr a, Monad m) => Int -> (Int -> m a) -> m (arr a) Source #
Construct an array of the given length by applying the monadic actino to each index.
generateMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> a) -> m (Mutable arr (PrimState m) a) Source #
Construct a mutable array of the given length by applying the function to each index.
iterateMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> a) -> a -> m (Mutable arr (PrimState m) a) Source #
Apply a function n
times to a value and construct a mutable array
where each consecutive element is the result of an additional
application of this function. The zeroth element is the original value.
write :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m () Source #
Write to a mutable array at the given index.
Monadic initialisation
replicateMutableM :: (PrimMonad m, Contiguous arr, Element arr a) => Int -> m a -> m (Mutable arr (PrimState m) a) Source #
performs the action n times, gathering the results.replicateMutableM
n act
generateMutableM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> m a) -> m (Mutable arr (PrimState m) a) Source #
Construct a mutable array of the given length by applying the monadic action to each index.
iterateMutableNM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> m a) -> a -> m (Mutable arr (PrimState m) a) Source #
Apply a monadic function n
times to a value and construct a mutable array
where each consecutive element is the result of an additional
application of this function. The zeroth element is the original value.
create :: (Contiguous arr, Element arr a) => (forall s. ST s (Mutable arr s a)) -> arr a Source #
Execute the monad action and freeze the resulting array.
createT :: (Contiguous arr, Element arr a, Traversable f) => (forall s. ST s (f (Mutable arr s a))) -> f (arr a) Source #
Execute the monadic action and freeze the resulting array.
Unfolding
unfoldrMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (b -> Maybe (a, b)) -> b -> m (Mutable arr (PrimState m) a) Source #
Enumeration
enumFromMutableN :: (Contiguous arr, Element arr a, PrimMonad m, Enum a) => a -> Int -> m (Mutable arr (PrimState m) a) Source #
Concatenation
append :: (Contiguous arr, Element arr a) => arr a -> arr a -> arr a Source #
Append two arrays.
Modifying arrays
Permutations
reverse :: (Contiguous arr, Element arr a) => arr a -> arr a Source #
Reverse the elements of an array.
reverseMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m () Source #
Reverse the elements of a mutable array, in-place.
:: (Contiguous arr, Element arr a, PrimMonad m) | |
=> Mutable arr (PrimState m) a | |
-> Int | start index |
-> Int | end index |
-> m () |
Reverse the elements of a slice of a mutable array, in-place.
Resizing
resize :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m (Mutable arr (PrimState m) b) Source #
Resize an array into one with the given size.
Elementwise operations
Mapping
map :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c Source #
Map over the elements of an array.
Note that because a new array must be created, the resulting array type can be different than the original.
map' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c Source #
Map strictly over the elements of an array.
Note that because a new array must be created, the resulting array type can be different than the original.
mapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Map over a mutable array, modifying the elements in place.
mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly map over a mutable array, modifying the elements in place.
imap :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c Source #
Map over the elements of an array with the index.
imap' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c Source #
Map strictly over the elements of an array with the index.
Note that because a new array must be created, the resulting array type can be different than the original.
imapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Map over a mutable array with indices, modifying the elements in place.
imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly map over a mutable array with indices, modifying the elements in place.
modify :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Modify the elements of a mutable array in-place.
modify' :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () Source #
Strictly modify the elements of a mutable array in-place.
mapMaybe :: forall arr1 arr2 a b. (Contiguous arr1, Element arr1 a, Contiguous arr2, Element arr2 b) => (a -> Maybe b) -> arr1 a -> arr2 b Source #
Zipping
zip :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 (a, b)) => arr1 a -> arr2 b -> arr3 (a, b) Source #
zip
takes two arrays and returns an array of
corresponding pairs.
zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')]
If one input array is shorter than the other, excess elements of the longer array are discarded:
zip [1] ['a', 'b'] = [(1, 'a')] zip [1, 2] ['a'] = [(1, 'a')]
zipWith :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 c) => (a -> b -> c) -> arr1 a -> arr2 b -> arr3 c Source #
Specific elements
swap :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> Int -> Int -> m () Source #
Swap the elements of the mutable array at the given indices.
Working with predicates
Filtering
filter :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> arr a Source #
Drop elements that do not satisfy the predicate.
ifilter :: (Contiguous arr, Element arr a) => (Int -> a -> Bool) -> arr a -> arr a Source #
Drop elements that do not satisfy the predicate which is applied to values and their indices.
catMaybes :: (Contiguous arr, Element arr a, Element arr (Maybe a)) => arr (Maybe a) -> arr a Source #
lefts :: forall arr a b. (Contiguous arr, Element arr a, Element arr (Either a b)) => arr (Either a b) -> arr a Source #
rights :: forall arr a b. (Contiguous arr, Element arr b, Element arr (Either a b)) => arr (Either a b) -> arr b Source #
partitionEithers :: forall arr a b. (Contiguous arr, Element arr a, Element arr b, Element arr (Either a b)) => arr (Either a b) -> (arr a, arr b) Source #
Searching
elem :: (Contiguous arr, Element arr a, Eq a) => a -> arr a -> Bool Source #
Does the element occur in the structure?
maximum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a Source #
The largest element of a structure.
minimum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a Source #
The least element of a structure.
maximumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a Source #
The largest element of a structure with respect to the given comparison function.
minimumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a Source #
The least element of a structure with respect to the given comparison function.
Comparing for equality
equals :: (Contiguous arr, Element arr b, Eq b) => arr b -> arr b -> Bool Source #
Test the two arrays for equality.
equalsMutable :: Contiguous arr => Mutable arr s a -> Mutable arr s a -> Bool Source #
Test the two mutable arrays for pointer equality. Does not check equality of elements.
same :: Contiguous arr => arr a -> arr a -> Bool Source #
This function does not behave deterministically. Optimization level and
inlining can affect its results. However, the one thing that can be counted
on is that if it returns True
, the two immutable arrays are definitely the
same. This is useful as shortcut for equality tests. However, keep in mind
that a result of False
tells us nothing about the arguments.
Folds
foldl :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b Source #
Left fold over the elements of an array.
foldl' :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b Source #
Strict left fold over the elements of an array.
foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b Source #
Right fold over the element of an array.
foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b Source #
Strict right fold over the elements of an array.
foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Monoidal fold over the element of an array.
foldMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m Source #
Strict left monoidal fold over the elements of an array.
ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b Source #
Strict left fold over the elements of an array, where the accumulating function cares about the index of the element.
ifoldr' :: (Contiguous arr, Element arr a) => (Int -> a -> b -> b) -> b -> arr a -> b Source #
Strict right fold over the elements of an array, where the accumulating function cares about the index of the element.
ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m Source #
Strict monoidal fold over the elements of an array.
foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b Source #
Strict left monadic fold over the elements of an array.
asum :: (Contiguous arr, Element arr (f a), Alternative f) => arr (f a) -> f a Source #
The sum of a collection of actions, generalizing concat
.
>>>
asum (C.fromList ['Just' "Hello", 'Nothing', Just "World"] :: Array String)
Just "Hello"
Traversals
traverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (a -> f b) -> arr1 a -> f (arr2 b) Source #
Map each element of the array to an action, evaluate these
actions from left to right, and collect the results.
For a version that ignores the results, see traverse_
.
traverse_ :: (Contiguous arr, Element arr a, Applicative f) => (a -> f b) -> arr a -> f () Source #
Map each element of the array to an action, evaluate these
actions from left to right, and ignore the results.
For a version that doesn't ignore the results, see traverse
.
itraverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (Int -> a -> f b) -> arr1 a -> f (arr2 b) Source #
Map each element of the array and its index to an action, evaluating these actions from left to right.
itraverse_ :: (Contiguous arr, Element arr a, Applicative f) => (Int -> a -> f b) -> arr a -> f () Source #
Map each element of the array and its index to an action,
evaluate these actions from left to right, and ignore the results.
For a version that doesn't ignore the results, see itraverse
.
traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> m b) -> arr1 a -> m (arr2 b) Source #
Map each element of the array to an action, evaluate these actions from left to right, and collect the results in a new array.
mapM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => (a -> m b) -> arr1 a -> m (arr2 b) Source #
Map each element of a structure to a monadic action,
evaluate these actions from left to right, and collect
the results. for a version that ignores the results see
mapM_
.
forM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => arr1 a -> (a -> m b) -> m (arr2 b) Source #
mapM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f () Source #
forM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f () Source #
for :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => arr1 a -> (a -> f b) -> f (arr2 b) Source #
for_ :: (Contiguous arr, Element arr a, Applicative f) => arr a -> (a -> f b) -> f () Source #
sequence :: (Contiguous arr1, Contiguous arr2, Element arr1 (f a), Element arr2 a, Applicative f) => arr1 (f a) -> f (arr2 a) Source #
Evaluate each action in the structure from left to right
and collect the results. For a version that ignores the
results see sequence_
.
sequence_ :: (Contiguous arr, Element arr (f a), Applicative f) => arr (f a) -> f () Source #
Evaluate each action in the structure from left to right
and ignore the results. For a version that doesn't ignore
the results see sequence
.
Typeclass method defaults
(<$) :: (Contiguous arr1, Contiguous arr2, Element arr1 b, Element arr2 a) => a -> arr1 b -> arr2 a Source #
Replace all locations in the input with the same value.
Equivalent to Data.Functor.<$
.
ap :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 (a -> b), Element arr2 a, Element arr3 b) => arr1 (a -> b) -> arr2 a -> arr3 b Source #
Sequential application.
Equivalent to Control.Applicative.<*>
.
Prefix sums (scans)
scanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b Source #
scanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b Source #
A strictly accumulating version of scanl
.
iscanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b Source #
A variant of scanl
whose function argument takes the current
index as an argument.
iscanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b Source #
A strictly accumulating version of iscanl
.
prescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b Source #
A prescan.
prescanl f z = init . scanl f z
Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6>
prescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b Source #
Like prescanl
, but with a strict accumulator.
iprescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b Source #
A variant of prescanl
where the function argument takes
the current index of the array as an additional argument.
iprescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b Source #
Like iprescanl
, but with a strict accumulator.
Conversions
Lists
fromList :: (Contiguous arr, Element arr a) => [a] -> arr a Source #
Convert a list into an array.
fromListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => [a] -> m (Mutable arr (PrimState m) a) Source #
Convert a list into a mutable array of the given length.
fromListMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) Source #
:: (Contiguous arr, Element arr a) | |
=> Int | length of list |
-> [a] | list |
-> arr a |
Create an array from a list. If the given length does not match the actual length, this function has undefined behavior.
unsafeFromListReverseN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a Source #
Create an array from a list, reversing the order of the elements. If the given length does not match the actual length, this function has undefined behavior.
unsafeFromListReverseMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) Source #
Create a mutable array from a list, reversing the order of the elements. If the given length does not match the actual length, this function has undefined behavior.
toList :: (Contiguous arr, Element arr a) => arr a -> [a] Source #
Convert an array to a list.
toListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m [a] Source #
Convert a mutable array to a list.
Other array types
convert :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 b) => arr1 b -> arr2 b Source #
Convert one type of array into another.
lift :: Contiguous arr => ArrayArray# -> arr b Source #
Lift an ArrayArray#
into an array.
unlift :: Contiguous arr => arr b -> ArrayArray# Source #
Unlift an array into an ArrayArray#
.
Between mutable and immutable variants
clone :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> arr b Source #
Clone a slice of an array.
cloneMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b) Source #
Clone a slice of a mutable array.
:: (Contiguous arr, PrimMonad m, Element arr b) | |
=> Mutable arr (PrimState m) b | destination array |
-> Int | offset into destination array |
-> arr b | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of an array into a mutable array.
:: (Contiguous arr, PrimMonad m, Element arr b) | |
=> Mutable arr (PrimState m) b | destination array |
-> Int | offset into destination array |
-> Mutable arr (PrimState m) b | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
Copy a slice of a mutable array into another mutable array. In the case that the destination and source arrays are the same, the regions may overlap.
freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b) Source #
Turn a mutable array into an immutable one with copying, using a slice of the mutable array.
thaw :: (Contiguous arr, PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b) Source #
Copy a slice of an immutable array into a new mutable array.
unsafeFreeze :: (Contiguous arr, PrimMonad m) => Mutable arr (PrimState m) b -> m (arr b) Source #
Turn a mutable array into an immutable one without copying. The mutable array should not be used after this conversion.
Hashing
liftHashWithSalt :: (Contiguous arr, Element arr a) => (Int -> a -> Int) -> Int -> arr a -> Int Source #
Lift an accumulating hash function over the elements of the array, returning the final accumulated hash.
Forcing an array and its contents
rnf :: (Contiguous arr, NFData a, Element arr a) => arr a -> () Source #
Reduce the array and all of its elements to WHNF.
Classes
class Contiguous (arr :: Type -> Type) Source #
The Contiguous
typeclass as an interface to a multitude of
contiguous structures.
empty, null, new, replicateMutable, index, index#, indexM, read, write, resize, size, sizeMutable, unsafeFreeze, freeze, thaw, copy, copyMutable, clone, cloneMutable, equals, equalsMutable, unlift, lift, singleton, doubleton, tripleton, rnf
type Mutable arr = (r :: Type -> Type -> Type) | r -> arr Source #
The Mutable counterpart to the array.
type Element arr :: Type -> Constraint Source #
The constraint needed to store elements in the array.
Instances
A typeclass that is satisfied by all types. This is used
used to provide a fake constraint for Array
and SmallArray
.
Instances
Always a Source # | |
Defined in Data.Primitive.Contiguous |
Re-Exports
Boxed arrays
Instances
data MutableArray s a #
Mutable boxed arrays associated with a primitive state token.
Instances
Eq (MutableArray s a) | |
Defined in Data.Primitive.Array (==) :: MutableArray s a -> MutableArray s a -> Bool # (/=) :: MutableArray s a -> MutableArray s a -> Bool # | |
(Typeable s, Typeable a) => Data (MutableArray s a) | |
Defined in Data.Primitive.Array 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 :: (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) # |
data SmallArray a #
Instances
data SmallMutableArray s a #
Instances
Eq (SmallMutableArray s a) | |
Defined in Data.Primitive.SmallArray (==) :: SmallMutableArray s a -> SmallMutableArray s a -> Bool # (/=) :: SmallMutableArray s a -> SmallMutableArray s a -> Bool # | |
(Typeable s, Typeable a) => Data (SmallMutableArray s a) | |
Defined in Data.Primitive.SmallArray gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SmallMutableArray s a -> c (SmallMutableArray s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (SmallMutableArray s a) # toConstr :: SmallMutableArray s a -> Constr # dataTypeOf :: SmallMutableArray s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (SmallMutableArray s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (SmallMutableArray s a)) # gmapT :: (forall b. Data b => b -> b) -> SmallMutableArray s a -> SmallMutableArray s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SmallMutableArray s a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SmallMutableArray s a -> r # gmapQ :: (forall d. Data d => d -> u) -> SmallMutableArray s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SmallMutableArray s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s 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.
Instances
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 convert 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
PrimUnlifted (MutablePrimArray s a) | |
Defined in Data.Primitive.Unlifted.Class type Unlifted (MutablePrimArray s a) :: TYPE UnliftedRep # toUnlifted# :: MutablePrimArray s a -> Unlifted (MutablePrimArray s a) # fromUnlifted# :: Unlifted (MutablePrimArray s a) -> MutablePrimArray s a # writeUnliftedArray# :: MutableArrayArray# s0 -> Int# -> MutablePrimArray s a -> State# s0 -> State# s0 # readUnliftedArray# :: MutableArrayArray# s0 -> Int# -> State# s0 -> (#State# s0, MutablePrimArray s a#) # indexUnliftedArray# :: ArrayArray# -> Int# -> MutablePrimArray s a # | |
type Unlifted (MutablePrimArray s a) | |
Defined in Data.Primitive.Unlifted.Class |
data UnliftedArray a #
Instances
data MutableUnliftedArray s a #
Instances
Eq (MutableUnliftedArray s a) | |
Defined in Data.Primitive.Unlifted.Array (==) :: MutableUnliftedArray s a -> MutableUnliftedArray s a -> Bool # (/=) :: MutableUnliftedArray s a -> MutableUnliftedArray s a -> Bool # |