Portability | non-portable |
---|---|

Stability | experimental |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Safe Haskell | None |

- data Vector
- data MVector
- class (Typeable2 mv, Typeable1 v, mv ~ Mutable v, MVector mv a, Vector v a) => Mixed mv v a | mv -> v, v -> mv where
- length :: Vector v a => v a -> Int
- null :: Vector v a => v a -> Bool
- (!) :: Vector v a => v a -> Int -> a
- (!?) :: Vector v a => v a -> Int -> Maybe a
- head :: Vector v a => v a -> a
- last :: Vector v a => v a -> a
- unsafeIndex :: Vector v a => v a -> Int -> a
- unsafeHead :: Vector v a => v a -> a
- unsafeLast :: Vector v a => v a -> a
- indexM :: (Monad m, Vector v a) => v a -> Int -> m a
- headM :: (Monad m, Vector v a) => v a -> m a
- lastM :: (Monad m, Vector v a) => v a -> m a
- unsafeIndexM :: (Monad m, Vector v a) => v a -> Int -> m a
- unsafeHeadM :: (Monad m, Vector v a) => v a -> m a
- unsafeLastM :: (Monad m, Vector v a) => v a -> m a
- slice :: Mixed u v a => Int -> Int -> v a -> Vector a
- init :: Mixed u v a => v a -> Vector a
- tail :: Mixed u v a => v a -> Vector a
- take :: Mixed u v a => Int -> v a -> Vector a
- drop :: Mixed u v a => Int -> v a -> Vector a
- splitAt :: Mixed u v a => Int -> v a -> (Vector a, Vector a)
- unsafeSlice :: Mixed u v a => Int -> Int -> v a -> Vector a
- unsafeInit :: Mixed u v a => v a -> Vector a
- unsafeTail :: Mixed u v a => v a -> Vector a
- unsafeTake :: Mixed u v a => Int -> v a -> Vector a
- unsafeDrop :: Mixed u v a => Int -> v a -> Vector a
- empty :: Vector a
- singleton :: a -> Vector a
- replicate :: Int -> a -> Vector a
- generate :: Int -> (Int -> a) -> Vector a
- iterateN :: Int -> (a -> a) -> a -> Vector a
- replicateM :: Monad m => Int -> m a -> m (Vector a)
- generateM :: Monad m => Int -> (Int -> m a) -> m (Vector a)
- create :: Mixed u v a => (forall s. ST s (u s a)) -> Vector a
- unfoldr :: (b -> Maybe (a, b)) -> b -> Vector a
- unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Vector a
- constructN :: Int -> (Vector a -> a) -> Vector a
- constructrN :: Int -> (Vector a -> a) -> Vector a
- enumFromN :: Num a => a -> Int -> Vector a
- enumFromStepN :: Num a => a -> a -> Int -> Vector a
- enumFromTo :: Enum a => a -> a -> Vector a
- enumFromThenTo :: Enum a => a -> a -> a -> Vector a
- cons :: Mixed u v a => a -> v a -> Vector a
- snoc :: Mixed u v a => v a -> a -> Vector a
- (++) :: (Mixed u v a, Mixed u' v' a) => v a -> v' a -> Vector a
- concat :: Mixed u v a => [v a] -> Vector a
- force :: Mixed u v a => v a -> Vector a
- (//) :: Mixed u v a => v a -> [(Int, a)] -> Vector a
- update :: (Mixed u v a, Vector v' (Int, a)) => v a -> v' (Int, a) -> Vector a
- update_ :: (Mixed u v a, Vector v' Int, Vector v'' a) => v a -> v' Int -> v'' a -> Vector a
- unsafeUpd :: Mixed u v a => v a -> [(Int, a)] -> Vector a
- unsafeUpdate :: (Mixed u v a, Vector v' (Int, a)) => v a -> v' (Int, a) -> Vector a
- unsafeUpdate_ :: (Mixed u v a, Vector v' Int, Vector v'' a) => v a -> v' Int -> v'' a -> Vector a
- accum :: Mixed u v a => (a -> b -> a) -> v a -> [(Int, b)] -> Vector a
- accumulate :: (Mixed u v a, Vector v' (Int, b)) => (a -> b -> a) -> v a -> v' (Int, b) -> Vector a
- accumulate_ :: (Mixed u v a, Vector v' Int, Vector v'' b) => (a -> b -> a) -> v a -> v' Int -> v'' b -> Vector a
- unsafeAccum :: Mixed u v a => (a -> b -> a) -> v a -> [(Int, b)] -> Vector a
- unsafeAccumulate :: (Mixed u v a, Vector v' (Int, b)) => (a -> b -> a) -> v a -> v' (Int, b) -> Vector a
- unsafeAccumulate_ :: (Mixed u v a, Vector v' Int, Vector v'' b) => (a -> b -> a) -> v a -> v' Int -> v'' b -> Vector a
- reverse :: Mixed u v a => v a -> Vector a
- backpermute :: (Mixed u v a, Vector v' Int) => v a -> v' Int -> Vector a
- unsafeBackpermute :: (Mixed u v a, Vector v' Int) => v a -> v' Int -> Vector a
- modify :: Mixed u v a => (forall s. u s a -> ST s ()) -> v a -> Vector a
- indexed :: (Vector v a, Mixed u v (Int, a)) => v a -> Vector (Int, a)
- map :: Vector v a => (a -> b) -> v a -> Vector b
- imap :: Vector v a => (Int -> a -> b) -> v a -> Vector b
- concatMap :: (Mixed u v b, Vector v' a) => (a -> v b) -> v' a -> Vector b
- mapM :: (Monad m, Vector v a) => (a -> m b) -> v a -> m (Vector b)
- mapM_ :: (Monad m, Vector v a) => (a -> m b) -> v a -> m ()
- forM :: (Monad m, Vector v a) => v a -> (a -> m b) -> m (Vector b)
- forM_ :: (Monad m, Vector v a) => v a -> (a -> m b) -> m ()
- zipWith :: (Vector va a, Vector vb b) => (a -> b -> c) -> va a -> vb b -> Vector c
- zipWith3 :: (Vector va a, Vector vb b, Vector vc c) => (a -> b -> c -> d) -> va a -> vb b -> vc c -> Vector d
- zipWith4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => (a -> b -> c -> d -> e) -> va a -> vb b -> vc c -> vd d -> Vector e
- zipWith5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => (a -> b -> c -> d -> e -> f) -> va a -> vb b -> vc c -> vd d -> ve e -> Vector f
- zipWith6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => (a -> b -> c -> d -> e -> f -> g) -> va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector g
- izipWith :: (Vector va a, Vector vb b) => (Int -> a -> b -> c) -> va a -> vb b -> Vector c
- izipWith3 :: (Vector va a, Vector vb b, Vector vc c) => (Int -> a -> b -> c -> d) -> va a -> vb b -> vc c -> Vector d
- izipWith4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => (Int -> a -> b -> c -> d -> e) -> va a -> vb b -> vc c -> vd d -> Vector e
- izipWith5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => (Int -> a -> b -> c -> d -> e -> f) -> va a -> vb b -> vc c -> vd d -> ve e -> Vector f
- izipWith6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => (Int -> a -> b -> c -> d -> e -> f -> g) -> va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector g
- zip :: (Vector va a, Vector vb b) => va a -> vb b -> Vector (a, b)
- zip3 :: (Vector va a, Vector vb b, Vector vc c) => va a -> vb b -> vc c -> Vector (a, b, c)
- zip4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => va a -> vb b -> vc c -> vd d -> Vector (a, b, c, d)
- zip5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => va a -> vb b -> vc c -> vd d -> ve e -> Vector (a, b, c, d, e)
- zip6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector (a, b, c, d, e, f)
- zipWithM :: (Monad m, Vector va a, Vector vb b) => (a -> b -> m c) -> va a -> vb b -> m (Vector c)
- zipWithM_ :: (Monad m, Vector va a, Vector vb b) => (a -> b -> m c) -> va a -> vb b -> m ()
- unzip :: Vector v (a, b) => v (a, b) -> (Vector a, Vector b)
- unzip3 :: Vector v (a, b, c) => v (a, b, c) -> (Vector a, Vector b, Vector c)
- unzip4 :: Vector v (a, b, c, d) => v (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d)
- unzip5 :: Vector v (a, b, c, d, e) => v (a, b, c, d, e) -> (Vector a, Vector b, Vector c, Vector d, Vector e)
- unzip6 :: Vector v (a, b, c, d, e, f) => v (a, b, c, d, e, f) -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)
- filter :: Mixed u v a => (a -> Bool) -> v a -> Vector a
- ifilter :: Mixed u v a => (Int -> a -> Bool) -> v a -> Vector a
- filterM :: (Monad m, Mixed u v a) => (a -> m Bool) -> v a -> m (Vector a)
- takeWhile :: Mixed u v a => (a -> Bool) -> v a -> Vector a
- dropWhile :: Mixed u v a => (a -> Bool) -> v a -> Vector a
- partition :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)
- unstablePartition :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)
- span :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)
- break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
- elem :: (Vector v a, Eq a) => a -> v a -> Bool
- notElem :: (Vector v a, Eq a) => a -> Vector a -> Bool
- find :: Vector v a => (a -> Bool) -> v a -> Maybe a
- findIndex :: Vector v a => (a -> Bool) -> v a -> Maybe Int
- findIndices :: Vector v a => (a -> Bool) -> v a -> Vector Int
- elemIndex :: (Vector v a, Eq a) => a -> v a -> Maybe Int
- elemIndices :: (Vector v a, Eq a) => a -> v a -> Vector Int
- foldl :: Vector v b => (a -> b -> a) -> a -> v b -> a
- foldl1 :: Vector v a => (a -> a -> a) -> v a -> a
- foldl' :: Vector v b => (a -> b -> a) -> a -> v b -> a
- foldl1' :: Vector v a => (a -> a -> a) -> v a -> a
- foldr :: Vector v a => (a -> b -> b) -> b -> v a -> b
- foldr1 :: Vector v a => (a -> a -> a) -> v a -> a
- foldr' :: Vector v a => (a -> b -> b) -> b -> v a -> b
- foldr1' :: Vector v a => (a -> a -> a) -> v a -> a
- ifoldl :: Vector v b => (a -> Int -> b -> a) -> a -> v b -> a
- ifoldl' :: Vector v b => (a -> Int -> b -> a) -> a -> v b -> a
- ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> b
- ifoldr' :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> b
- all :: Vector v a => (a -> Bool) -> v a -> Bool
- any :: Vector v a => (a -> Bool) -> v a -> Bool
- and :: Vector v Bool => v Bool -> Bool
- or :: Vector v Bool => v Bool -> Bool
- sum :: (Vector v a, Num a) => v a -> a
- product :: (Vector v a, Num a) => v a -> a
- maximum :: (Vector v a, Ord a) => v a -> a
- maximumBy :: Vector v a => (a -> a -> Ordering) -> v a -> a
- minimum :: (Vector v a, Ord a) => v a -> a
- minimumBy :: Vector v a => (a -> a -> Ordering) -> v a -> a
- minIndex :: (Vector v a, Ord a) => v a -> Int
- minIndexBy :: Vector v a => (a -> a -> Ordering) -> v a -> Int
- maxIndex :: (Vector v a, Ord a) => v a -> Int
- maxIndexBy :: Vector v a => (a -> a -> Ordering) -> v a -> Int
- foldM :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m a
- foldM' :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m a
- fold1M :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m a
- fold1M' :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m a
- foldM_ :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m ()
- foldM'_ :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m ()
- fold1M_ :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m ()
- fold1M'_ :: (Vector v a, Monad m) => (a -> a -> m a) -> Vector a -> m ()
- sequence :: (Mixed u v (m a), Monad m) => v (m a) -> m (Vector a)
- sequence_ :: (Vector v (m a), Monad m) => v (m a) -> m ()
- prescanl :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- prescanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- postscanl :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- postscanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- scanl :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- scanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector a
- scanl1 :: Mixed u v a => (a -> a -> a) -> v a -> Vector a
- scanl1' :: Mixed u v a => (a -> a -> a) -> v a -> Vector a
- prescanr :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- prescanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- postscanr :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- postscanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- scanr :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- scanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector b
- scanr1 :: Mixed u v a => (a -> a -> a) -> v a -> Vector a
- scanr1' :: (a -> a -> a) -> Vector a -> Vector a
- toList :: Vector v a => v a -> [a]
- fromList :: [a] -> Vector a
- fromListN :: Int -> [a] -> Vector a
- convert :: (Vector v a, Vector w a) => v a -> w a
- freeze :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> m (Vector a)
- thaw :: (PrimMonad m, Mixed u v a) => v a -> m (MVector (PrimState m) a)
- copy :: (PrimMonad m, Mixed u v a, Mixed u' v' a) => u (PrimState m) a -> v' a -> m ()
- unsafeFreeze :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> m (Vector a)
- unsafeThaw :: (PrimMonad m, Mixed u v a) => v a -> m (MVector (PrimState m) a)
- unsafeCopy :: (PrimMonad m, Mixed u v a, Mixed u' v' a) => u (PrimState m) a -> v' a -> m ()

# Mixed vectors

Monad Vector | |

Functor Vector | |

Typeable1 Vector | |

MonadPlus Vector | |

Applicative Vector | |

Foldable Vector | |

Traversable Vector | |

Alternative Vector | |

Vector Vector a | |

Mixed MVector Vector a | |

Eq a => Eq (Vector a) | |

Data a => Data (Vector a) | |

Ord a => Ord (Vector a) | |

Read a => Read (Vector a) | |

Show a => Show (Vector a) | |

Monoid (Vector a) |

A `MVector s a`

is mutable vector that could have any vector type underneath

class (Typeable2 mv, Typeable1 v, mv ~ Mutable v, MVector mv a, Vector v a) => Mixed mv v a | mv -> v, v -> mv whereSource

Vector doesn't provide a way to recover the type of the immutable vector from the mutable vector type

This would otherwise prevent us from finishing the implementation of `basicUnsafeFreeze`

in `Vector`

This class captures the invariants necessary to `hide`

the choice of vector type from the user in such
a way that we can go from mutable vector to immutabl vector and back again.

# Accessors

## Length information

## Indexing

unsafeIndex :: Vector v a => v a -> Int -> aSource

*O(1)* Unsafe indexing without bounds checking

unsafeHead :: Vector v a => v a -> aSource

*O(1)* First element without checking if the vector is empty

unsafeLast :: Vector v a => v a -> aSource

*O(1)* Last element without checking if the vector is empty

## Monadic indexing

indexM :: (Monad m, Vector v a) => v a -> Int -> m aSource

*O(1)* Indexing in a monad.

The monad allows operations to be strict in the vector when necessary. Suppose vector copying is implemented like this:

copy mv v = ... write mv i (v ! i) ...

For lazy vectors, `v ! i`

would 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.

headM :: (Monad m, Vector v a) => v a -> m aSource

*O(1)* First element of a vector in a monad. See `indexM`

for an
explanation of why this is useful.

lastM :: (Monad m, Vector v a) => v a -> m aSource

*O(1)* Last element of a vector in a monad. See `indexM`

for an
explanation of why this is useful.

unsafeIndexM :: (Monad m, Vector v a) => v a -> Int -> m aSource

*O(1)* Indexing in a monad without bounds checks. See `indexM`

for an
explanation of why this is useful.

unsafeHeadM :: (Monad m, Vector v a) => v a -> m aSource

*O(1)* First element in a monad without checking for empty vectors.
See `indexM`

for an explanation of why this is useful.

unsafeLastM :: (Monad m, Vector v a) => v a -> m aSource

*O(1)* Last element in a monad without checking for empty vectors.
See `indexM`

for an explanation of why this is useful.

## Extracting subvectors (slicing)

*O(1)* Yield a slice of the vector without copying it. The vector must
contain at least `i+n`

elements.

init :: Mixed u v a => v a -> Vector aSource

*O(1)* Yield all but the last element without copying. The vector may not
be empty.

tail :: Mixed u v a => v a -> Vector aSource

*O(1)* Yield all but the first element without copying. The vector may not
be empty.

take :: Mixed u v a => Int -> v a -> Vector aSource

*O(1)* Yield at the first `n`

elements without copying. The vector may
contain less than `n`

elements in which case it is returned unchanged.

drop :: Mixed u v a => Int -> v a -> Vector aSource

*O(1)* Yield all but the first `n`

elements without copying. The vector may
contain less than `n`

elements in which case an empty vector is returned.

*O(1)* Yield a slice of the vector without copying. The vector must
contain at least `i+n`

elements but this is not checked.

unsafeInit :: Mixed u v a => v a -> Vector aSource

*O(1)* Yield all but the last element without copying. The vector may not
be empty but this is not checked.

unsafeTail :: Mixed u v a => v a -> Vector aSource

*O(1)* Yield all but the first element without copying. The vector may not
be empty but this is not checked.

unsafeTake :: Mixed u v a => Int -> v a -> Vector aSource

*O(1)* Yield the first `n`

elements without copying. The vector must
contain at least `n`

elements but this is not checked.

unsafeDrop :: Mixed u v a => Int -> v a -> Vector aSource

*O(1)* Yield all but the first `n`

elements without copying. The vector
must contain at least `n`

elements but this is not checked.

# Construction

## Initialisation

replicate :: Int -> a -> Vector aSource

*O(n)* Vector of the given length with the same value in each position

generate :: Int -> (Int -> a) -> Vector aSource

*O(n)* Construct a vector of the given length by applying the function to
each index

iterateN :: Int -> (a -> a) -> a -> Vector aSource

*O(n)* Apply function n times to value. Zeroth element is original value.

## Monadic initialisation

replicateM :: Monad m => Int -> m a -> m (Vector a)Source

*O(n)* Execute the monadic action the given number of times and store the
results in a vector.

generateM :: Monad m => Int -> (Int -> m a) -> m (Vector a)Source

*O(n)* Construct a vector of the given length by applying the monadic
action to each index

create :: Mixed u v a => (forall s. ST s (u s a)) -> Vector aSource

Execute the monadic action and freeze the resulting vector.

create (do { v <- new 2; write v 0 'a'; write v 1 'b'; return v }) = <`a`

,`b`

>

## Unfolding

constructN :: Int -> (Vector a -> a) -> Vector aSource

*O(n)* Construct a vector with `n`

elements by repeatedly applying the
generator function to the already constructed part of the vector.

constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in f <a,b,c>

constructrN :: Int -> (Vector a -> a) -> Vector aSource

*O(n)* Construct a vector with `n`

elements from right to left by
repeatedly applying the generator function to the already constructed part
of the vector.

constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in f <c,b,a>

## Enumeration

enumFromN :: Num a => a -> Int -> Vector aSource

*O(n)* Yield a vector of the given length containing the values `x`

, `x+1`

etc. This operation is usually more efficient than `enumFromTo`

.

enumFromN 5 3 = <5,6,7>

enumFromStepN :: Num a => a -> a -> Int -> Vector aSource

*O(n)* Yield a vector of the given length containing the values `x`

, `x+y`

,
`x+y+y`

etc. This operations is usually more efficient than `enumFromThenTo`

.

enumFromStepN 1 0.1 5 = <1,1.1,1.2,1.3,1.4>

enumFromTo :: Enum a => a -> a -> Vector aSource

*O(n)* Enumerate values from `x`

to `y`

.

*WARNING:* This operation can be very inefficient. If at all possible, use
`enumFromN`

instead.

enumFromThenTo :: Enum a => a -> a -> a -> Vector aSource

*O(n)* Enumerate values from `x`

to `y`

with a specific step `z`

.

*WARNING:* This operation can be very inefficient. If at all possible, use
`enumFromStepN`

instead.

## Concatenation

## Restricting memory usage

force :: Mixed u v a => v a -> Vector aSource

*O(n)* Yield the argument but force it not to retain any extra memory,
possibly by copying it.

This is especially useful when dealing with slices. For example:

force (slice 0 2 <huge vector>)

Here, the slice retains a reference to the huge vector. Forcing it creates a copy of just the elements that belong to the slice and allows the huge vector to be garbage collected.

# Modifying vectors

## Bulk updates

:: Mixed u v a | |

=> v a | initial vector (of length |

-> [(Int, a)] | list of index/value pairs (of length |

-> Vector a |

*O(m+n)* For each pair `(i,a)`

from the list, replace the vector
element at position `i`

by `a`

.

<5,9,2,7> // [(2,1),(0,3),(2,8)] = <3,9,8,7>

:: (Mixed u v a, Vector v' (Int, a)) | |

=> v a | initial vector (of length |

-> v' (Int, a) | vector of index/value pairs (of length |

-> Vector a |

*O(m+n)* For each pair `(i,a)`

from the vector of index/value pairs,
replace the vector element at position `i`

by `a`

.

update <5,9,2,7> <(2,1),(0,3),(2,8)> = <3,9,8,7>

:: (Mixed u v a, Vector v' Int, Vector v'' a) | |

=> v a | initial vector (of length |

-> v' Int | index vector (of length |

-> v'' a | value vector (of length |

-> Vector a |

*O(m+min(n1,n2))* For each index `i`

from the index vector and the
corresponding value `a`

from the value vector, replace the element of the
initial vector at position `i`

by `a`

.

update_ <5,9,2,7> <2,0,2> <1,3,8> = <3,9,8,7>

The function `update`

provides the same functionality and is usually more
convenient.

update_ xs is ys =`update`

xs (`zip`

is ys)

unsafeUpd :: Mixed u v a => v a -> [(Int, a)] -> Vector aSource

Same as (`//`

) but without bounds checking.

unsafeUpdate :: (Mixed u v a, Vector v' (Int, a)) => v a -> v' (Int, a) -> Vector aSource

Same as `update`

but without bounds checking.

unsafeUpdate_ :: (Mixed u v a, Vector v' Int, Vector v'' a) => v a -> v' Int -> v'' a -> Vector aSource

Same as `update_`

but without bounds checking.

## Accumulations

:: Mixed u v a | |

=> (a -> b -> a) | accumulating function |

-> v a | initial vector (of length |

-> [(Int, b)] | list of index/value pairs (of length |

-> Vector a |

*O(m+n)* For each pair `(i,b)`

from the list, replace the vector element
`a`

at position `i`

by `f a b`

.

accum (+) <5,9,2> [(2,4),(1,6),(0,3),(1,7)] = <5+3, 9+6+7, 2+4>

:: (Mixed u v a, Vector v' (Int, b)) | |

=> (a -> b -> a) | accumulating function |

-> v a | initial vector (of length |

-> v' (Int, b) | vector of index/value pairs (of length |

-> Vector a |

*O(m+n)* For each pair `(i,b)`

from the vector of pairs, replace the vector
element `a`

at position `i`

by `f a b`

.

accumulate (+) <5,9,2> <(2,4),(1,6),(0,3),(1,7)> = <5+3, 9+6+7, 2+4>

:: (Mixed u v a, Vector v' Int, Vector v'' b) | |

=> (a -> b -> a) | accumulating function |

-> v a | initial vector (of length |

-> v' Int | index vector (of length |

-> v'' b | value vector (of length |

-> Vector a |

*O(m+min(n1,n2))* For each index `i`

from the index vector and the
corresponding value `b`

from the the value vector,
replace the element of the initial vector at
position `i`

by `f a b`

.

accumulate_ (+) <5,9,2> <2,1,0,1> <4,6,3,7> = <5+3, 9+6+7, 2+4>

The function `accumulate`

provides the same functionality and is usually more
convenient.

accumulate_ f as is bs =`accumulate`

f as (`zip`

is bs)

unsafeAccum :: Mixed u v a => (a -> b -> a) -> v a -> [(Int, b)] -> Vector aSource

Same as `accum`

but without bounds checking.

unsafeAccumulate :: (Mixed u v a, Vector v' (Int, b)) => (a -> b -> a) -> v a -> v' (Int, b) -> Vector aSource

Same as `accumulate`

but without bounds checking.

unsafeAccumulate_ :: (Mixed u v a, Vector v' Int, Vector v'' b) => (a -> b -> a) -> v a -> v' Int -> v'' b -> Vector aSource

Same as `accumulate_`

but without bounds checking.

## Permutations

unsafeBackpermute :: (Mixed u v a, Vector v' Int) => v a -> v' Int -> Vector aSource

Same as `backpermute`

but without bounds checking.

## Safe destructive updates

modify :: Mixed u v a => (forall s. u s a -> ST s ()) -> v a -> Vector aSource

Apply a destructive operation to a vector. The operation will be performed in place if it is safe to do so and will modify a copy of the vector otherwise.

` modify (\v -> write v 0 'x') (``replicate`

3 'a') = <'x','a','a'>

# Elementwise operations

## Indexing

indexed :: (Vector v a, Mixed u v (Int, a)) => v a -> Vector (Int, a)Source

*O(n)* Pair each element in a vector with its index

## Mapping

imap :: Vector v a => (Int -> a -> b) -> v a -> Vector bSource

*O(n)* Apply a function to every element of a vector and its index

concatMap :: (Mixed u v b, Vector v' a) => (a -> v b) -> v' a -> Vector bSource

Map a function over a vector and concatenate the results.

## Monadic mapping

mapM :: (Monad m, Vector v a) => (a -> m b) -> v a -> m (Vector b)Source

*O(n)* Apply the monadic action to all elements of the vector, yielding a
vector of results

mapM_ :: (Monad m, Vector v a) => (a -> m b) -> v a -> m ()Source

*O(n)* Apply the monadic action to all elements of a vector and ignore the
results

forM :: (Monad m, Vector v a) => v a -> (a -> m b) -> m (Vector b)Source

*O(n)* Apply the monadic action to all elements of the vector, yielding a
vector of results. Equvalent to `flip `

.
`mapM`

forM_ :: (Monad m, Vector v a) => v a -> (a -> m b) -> m ()Source

*O(n)* Apply the monadic action to all elements of a vector and ignore the
results. Equivalent to `flip `

.
`mapM_`

## Zipping

zipWith :: (Vector va a, Vector vb b) => (a -> b -> c) -> va a -> vb b -> Vector cSource

*O(min(m,n))* Zip two vectors with the given function.

zipWith3 :: (Vector va a, Vector vb b, Vector vc c) => (a -> b -> c -> d) -> va a -> vb b -> vc c -> Vector dSource

Zip three vectors with the given function.

zipWith4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => (a -> b -> c -> d -> e) -> va a -> vb b -> vc c -> vd d -> Vector eSource

zipWith5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => (a -> b -> c -> d -> e -> f) -> va a -> vb b -> vc c -> vd d -> ve e -> Vector fSource

zipWith6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => (a -> b -> c -> d -> e -> f -> g) -> va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector gSource

izipWith :: (Vector va a, Vector vb b) => (Int -> a -> b -> c) -> va a -> vb b -> Vector cSource

*O(min(m,n))* Zip two vectors with a function that also takes the
elements' indices.

izipWith3 :: (Vector va a, Vector vb b, Vector vc c) => (Int -> a -> b -> c -> d) -> va a -> vb b -> vc c -> Vector dSource

Zip three vectors and their indices with the given function.

izipWith4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => (Int -> a -> b -> c -> d -> e) -> va a -> vb b -> vc c -> vd d -> Vector eSource

izipWith5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => (Int -> a -> b -> c -> d -> e -> f) -> va a -> vb b -> vc c -> vd d -> ve e -> Vector fSource

izipWith6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => (Int -> a -> b -> c -> d -> e -> f -> g) -> va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector gSource

zip :: (Vector va a, Vector vb b) => va a -> vb b -> Vector (a, b)Source

Elementwise pairing of array elements.

zip3 :: (Vector va a, Vector vb b, Vector vc c) => va a -> vb b -> vc c -> Vector (a, b, c)Source

zip together three vectors into a vector of triples

zip4 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d) => va a -> vb b -> vc c -> vd d -> Vector (a, b, c, d)Source

zip5 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e) => va a -> vb b -> vc c -> vd d -> ve e -> Vector (a, b, c, d, e)Source

zip6 :: (Vector va a, Vector vb b, Vector vc c, Vector vd d, Vector ve e, Vector vf f) => va a -> vb b -> vc c -> vd d -> ve e -> vf f -> Vector (a, b, c, d, e, f)Source

## Monadic zipping

zipWithM :: (Monad m, Vector va a, Vector vb b) => (a -> b -> m c) -> va a -> vb b -> m (Vector c)Source

*O(min(m,n))* Zip the two vectors with the monadic action and yield a
vector of results

zipWithM_ :: (Monad m, Vector va a, Vector vb b) => (a -> b -> m c) -> va a -> vb b -> m ()Source

*O(min(m,n))* Zip the two vectors with the monadic action and ignore the
results

## Unzipping

unzip :: Vector v (a, b) => v (a, b) -> (Vector a, Vector b)Source

*O(min(m,n))* Unzip a vector of pairs.

unzip5 :: Vector v (a, b, c, d, e) => v (a, b, c, d, e) -> (Vector a, Vector b, Vector c, Vector d, Vector e)Source

unzip6 :: Vector v (a, b, c, d, e, f) => v (a, b, c, d, e, f) -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)Source

# Working with predicates

## Filtering

filter :: Mixed u v a => (a -> Bool) -> v a -> Vector aSource

*O(n)* Drop elements that do not satisfy the predicate

ifilter :: Mixed u v a => (Int -> a -> Bool) -> v a -> Vector aSource

*O(n)* Drop elements that do not satisfy the predicate which is applied to
values and their indices

filterM :: (Monad m, Mixed u v a) => (a -> m Bool) -> v a -> m (Vector a)Source

*O(n)* Drop elements that do not satisfy the monadic predicate

takeWhile :: Mixed u v a => (a -> Bool) -> v a -> Vector aSource

*O(n)* Yield the longest prefix of elements satisfying the predicate
without copying.

dropWhile :: Mixed u v a => (a -> Bool) -> v a -> Vector aSource

*O(n)* Drop the longest prefix of elements that satisfy the predicate
without copying.

## Partitioning

partition :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)Source

*O(n)* Split the vector in two parts, the first one containing those
elements that satisfy the predicate and the second one those that don't. The
relative order of the elements is preserved at the cost of a sometimes
reduced performance compared to `unstablePartition`

.

unstablePartition :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)Source

*O(n)* Split the vector in two parts, the first one containing those
elements that satisfy the predicate and the second one those that don't.
The order of the elements is not preserved but the operation is often
faster than `partition`

.

span :: Mixed u v a => (a -> Bool) -> v a -> (Vector a, Vector a)Source

*O(n)* Split the vector into the longest prefix of elements that satisfy
the predicate and the rest without copying.

break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)Source

*O(n)* Split the vector into the longest prefix of elements that do not
satisfy the predicate and the rest without copying.

## Searching

notElem :: (Vector v a, Eq a) => a -> Vector a -> BoolSource

*O(n)* Check if the vector does not contain an element (inverse of `elem`

)

findIndices :: Vector v a => (a -> Bool) -> v a -> Vector IntSource

*O(n)* Yield the indices of elements satisfying the predicate in ascending
order.

elemIndices :: (Vector v a, Eq a) => a -> v a -> Vector IntSource

*O(n)* Yield the indices of all occurences of the given element in
ascending order. This is a specialised version of `findIndices`

.

# Folding

foldl1' :: Vector v a => (a -> a -> a) -> v a -> aSource

*O(n)* Left fold on non-empty vectors with strict accumulator

foldr' :: Vector v a => (a -> b -> b) -> b -> v a -> bSource

*O(n)* Right fold with a strict accumulator

foldr1' :: Vector v a => (a -> a -> a) -> v a -> aSource

*O(n)* Right fold on non-empty vectors with strict accumulator

ifoldl :: Vector v b => (a -> Int -> b -> a) -> a -> v b -> aSource

*O(n)* Left fold (function applied to each element and its index)

ifoldl' :: Vector v b => (a -> Int -> b -> a) -> a -> v b -> aSource

*O(n)* Left fold with strict accumulator (function applied to each element
and its index)

ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> bSource

*O(n)* Right fold (function applied to each element and its index)

ifoldr' :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> bSource

*O(n)* Right fold with strict accumulator (function applied to each
element and its index)

## Specialised folds

all :: Vector v a => (a -> Bool) -> v a -> BoolSource

*O(n)* Check if all elements satisfy the predicate.

any :: Vector v a => (a -> Bool) -> v a -> BoolSource

*O(n)* Check if any element satisfies the predicate.

maximum :: (Vector v a, Ord a) => v a -> aSource

*O(n)* Yield the maximum element of the vector. The vector may not be
empty.

maximumBy :: Vector v a => (a -> a -> Ordering) -> v a -> aSource

*O(n)* Yield the maximum element of the vector according to the given
comparison function. The vector may not be empty.

minimum :: (Vector v a, Ord a) => v a -> aSource

*O(n)* Yield the minimum element of the vector. The vector may not be
empty.

minimumBy :: Vector v a => (a -> a -> Ordering) -> v a -> aSource

*O(n)* Yield the minimum element of the vector according to the given
comparison function. The vector may not be empty.

minIndex :: (Vector v a, Ord a) => v a -> IntSource

*O(n)* Yield the index of the minimum element of the vector. The vector
may not be empty.

minIndexBy :: Vector v a => (a -> a -> Ordering) -> v a -> IntSource

*O(n)* Yield the index of the minimum element of the vector according to
the given comparison function. The vector may not be empty.

maxIndex :: (Vector v a, Ord a) => v a -> IntSource

*O(n)* Yield the index of the maximum element of the vector. The vector
may not be empty.

maxIndexBy :: Vector v a => (a -> a -> Ordering) -> v a -> IntSource

*O(n)* Yield the index of the maximum element of the vector according to
the given comparison function. The vector may not be empty.

## Monadic folds

foldM' :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m aSource

*O(n)* Monadic fold with strict accumulator

fold1M :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m aSource

*O(n)* Monadic fold over non-empty vectors

fold1M' :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m aSource

*O(n)* Monadic fold over non-empty vectors with strict accumulator

foldM_ :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m ()Source

*O(n)* Monadic fold that discards the result

foldM'_ :: (Vector v b, Monad m) => (a -> b -> m a) -> a -> v b -> m ()Source

*O(n)* Monadic fold with strict accumulator that discards the result

fold1M_ :: (Vector v a, Monad m) => (a -> a -> m a) -> v a -> m ()Source

*O(n)* Monadic fold over non-empty vectors that discards the result

fold1M'_ :: (Vector v a, Monad m) => (a -> a -> m a) -> Vector a -> m ()Source

*O(n)* Monadic fold over non-empty vectors with strict accumulator
that discards the result

## Monadic sequencing

sequence :: (Mixed u v (m a), Monad m) => v (m a) -> m (Vector a)Source

Evaluate each action and collect the results

sequence_ :: (Vector v (m a), Monad m) => v (m a) -> m ()Source

Evaluate each action and discard the results

# Prefix sums (scans)

prescanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector aSource

*O(n)* Prescan with strict accumulator

postscanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector aSource

*O(n)* Scan with strict accumulator

scanl :: Vector v b => (a -> b -> a) -> a -> v b -> Vector aSource

*O(n)* Haskell-style scan

scanl f z <x1,...,xn> = <y1,...,y(n+1)> where y1 = z yi = f y(i-1) x(i-1)

Example: `scanl (+) 0 <1,2,3,4> = <0,1,3,6,10>`

scanl' :: Vector v b => (a -> b -> a) -> a -> v b -> Vector aSource

*O(n)* Haskell-style scan with strict accumulator

scanl1 :: Mixed u v a => (a -> a -> a) -> v a -> Vector aSource

*O(n)* Scan over a non-empty vector

scanl f <x1,...,xn> = <y1,...,yn> where y1 = x1 yi = f y(i-1) xi

scanl1' :: Mixed u v a => (a -> a -> a) -> v a -> Vector aSource

*O(n)* Scan over a non-empty vector with a strict accumulator

prescanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector bSource

*O(n)* Right-to-left prescan with strict accumulator

postscanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector bSource

*O(n)* Right-to-left scan with strict accumulator

scanr :: Vector v a => (a -> b -> b) -> b -> v a -> Vector bSource

*O(n)* Right-to-left Haskell-style scan

scanr' :: Vector v a => (a -> b -> b) -> b -> v a -> Vector bSource

*O(n)* Right-to-left Haskell-style scan with strict accumulator

scanr1 :: Mixed u v a => (a -> a -> a) -> v a -> Vector aSource

*O(n)* Right-to-left scan over a non-empty vector

scanr1' :: (a -> a -> a) -> Vector a -> Vector aSource

*O(n)* Right-to-left scan over a non-empty vector with a strict
accumulator

# Conversions

## Lists

## Other vector types

## Mutable vectors

freeze :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> m (Vector a)Source

*O(n)* Yield an immutable copy of the mutable vector.

thaw :: (PrimMonad m, Mixed u v a) => v a -> m (MVector (PrimState m) a)Source

*O(n)* Yield a mutable copy of the immutable vector.

copy :: (PrimMonad m, Mixed u v a, Mixed u' v' a) => u (PrimState m) a -> v' a -> m ()Source

*O(n)* Copy an immutable vector into a mutable one. The two vectors must
have the same length.

unsafeFreeze :: (PrimMonad m, Mixed u v a) => u (PrimState m) a -> m (Vector a)Source

*O(1)* Unsafe convert a mutable vector to an immutable one without
copying. The mutable vector may not be used after this operation.