|
| Data.Vector.Generic | | Portability | non-portable | | Stability | experimental | | Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |
|
|
|
|
|
| Description |
| Generic interface to pure vectors
|
|
| Synopsis |
|
| class Vector v a where | | | | length :: Vector v a => v a -> Int | | | null :: Vector v a => v a -> Bool | | | empty :: Vector v a => v a | | | singleton :: Vector v a => a -> v a | | | cons :: Vector v a => a -> v a -> v a | | | snoc :: Vector v a => v a -> a -> v a | | | replicate :: Vector v a => Int -> a -> v a | | | (++) :: Vector v a => v a -> v a -> v a | | | copy :: Vector v a => v a -> v a | | | (!) :: Vector v a => v a -> Int -> a | | | head :: Vector v a => v a -> a | | | last :: Vector v a => v a -> a | | | indexM :: (Vector v a, Monad m) => v a -> Int -> m a | | | headM :: (Vector v a, Monad m) => v a -> m a | | | lastM :: (Vector v a, Monad m) => v a -> m a | | | slice :: Vector v a => v a -> Int -> Int -> v a | | | init :: Vector v a => v a -> v a | | | tail :: Vector v a => v a -> v a | | | take :: Vector v a => Int -> v a -> v a | | | drop :: Vector v a => Int -> v a -> v a | | | accum :: Vector v a => (a -> b -> a) -> v a -> [(Int, b)] -> v a | | | (//) :: Vector v a => v a -> [(Int, a)] -> v a | | | update :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a | | | backpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a | | | reverse :: Vector v a => v a -> v a | | | map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b | | | concatMap :: (Vector v a, Vector v b) => (a -> v b) -> v a -> v b | | | zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c | | | zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v d | | | zip :: (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) | | | zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c) | | | unzip :: (Vector v a, Vector v b, Vector v (a, b)) => v (a, b) -> (v a, v b) | | | unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c) | | | eq :: (Vector v a, Eq a) => v a -> v a -> Bool | | | cmp :: (Vector v a, Ord a) => v a -> v a -> Ordering | | | filter :: Vector v a => (a -> Bool) -> v a -> v a | | | takeWhile :: Vector v a => (a -> Bool) -> v a -> v a | | | dropWhile :: Vector v a => (a -> Bool) -> v a -> v a | | | elem :: (Vector v a, Eq a) => a -> v a -> Bool | | | notElem :: (Vector v a, Eq a) => a -> v a -> Bool | | | find :: Vector v a => (a -> Bool) -> v a -> Maybe a | | | findIndex :: Vector v a => (a -> Bool) -> v a -> Maybe 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 | | | 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 | | | minimum :: (Vector v a, Ord a) => v a -> a | | | unfoldr :: Vector v a => (b -> Maybe (a, b)) -> b -> v a | | | prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | prescanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | postscanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | scanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a | | | scanl1 :: Vector v a => (a -> a -> a) -> v a -> v a | | | scanl1' :: Vector v a => (a -> a -> a) -> v a -> v a | | | enumFromTo :: (Vector v a, Enum a) => a -> a -> v a | | | enumFromThenTo :: (Vector v a, Enum a) => a -> a -> a -> v a | | | toList :: Vector v a => v a -> [a] | | | fromList :: Vector v a => [a] -> v a | | | stream :: Vector v a => v a -> Stream a | | | unstream :: Vector v a => Stream a -> v a | | | new :: Vector v a => New a -> v a |
|
|
|
| Immutable vectors
|
|
|
| Class of immutable vectors.
| | | Methods | | | Construct a pure vector from a monadic initialiser (not fusible!)
| | | | Length of the vector (not fusible!)
| | | | Yield a part of the vector without copying it. No range checks!
| | | Yield the element at the given position in a monad. The monad allows us
to be strict in the vector if we want. Suppose we had
unsafeIndex :: v a -> Int -> a
instead. Now, if we wanted to copy a vector, we'd do something like
copy mv v ... = ... unsafeWrite mv i (unsafeIndex v i) ...
For lazy vectors, the indexing would not be evaluated which means that we
would retain a reference to the original vector in each element we write.
This is not what we want!
With unsafeIndexM, we can do
copy mv v ... = ... case unsafeIndexM v i of
Box x -> unsafeWrite mv i x ...
which does not have this problem because indexing (but not the returned
element!) is evaluated immediately.
|
| | Instances | |
|
|
| Length information
|
|
|
|
|
|
| Construction
|
|
|
| Empty vector
|
|
|
| Vector with exaclty one element
|
|
|
| Prepend an element
|
|
|
| Append an element
|
|
|
| Vector of the given length with the given value in each position
|
|
|
| Concatenate two vectors
|
|
|
| Create a copy of a vector. Useful when dealing with slices.
|
|
| Accessing individual elements
|
|
|
| Indexing
|
|
|
| First element
|
|
|
| Last element
|
|
|
| Monadic indexing which can be strict in the vector while remaining lazy in
the element.
|
|
|
|
|
|
| Subvectors
|
|
|
| :: Vector v a | | | => v a | | | -> Int | starting index
| | -> Int | length
| | -> v a | | | Yield a part of the vector without copying it. Safer version of
unsafeSlice.
|
|
|
|
| Yield all but the last element without copying.
|
|
|
| All but the first element (without copying).
|
|
|
| Yield the first n elements without copying.
|
|
|
| Yield all but the first n elements without copying.
|
|
| Permutations
|
|
|
|
|
|
|
|
|
|
|
|
| Mapping
|
|
|
| Map a function over a vector
|
|
|
|
| Zipping and unzipping
|
|
|
| Zip two vectors with the given function.
|
|
|
| Zip three vectors with the given function.
|
|
|
|
|
|
|
|
|
|
| Comparisons
|
|
|
|
|
|
| Filtering
|
|
|
| Drop elements which do not satisfy the predicate
|
|
|
| Yield the longest prefix of elements satisfying the predicate.
|
|
|
| Drop the longest prefix of elements that satisfy the predicate.
|
|
| Searching
|
|
|
| Check whether the vector contains an element
|
|
|
| Inverse of elem
|
|
|
| Yield Just the first element matching the predicate or Nothing if no
such element exists.
|
|
|
| Yield Just the index of the first element matching the predicate or
Nothing if no such element exists.
|
|
| Folding
|
|
|
| Left fold
|
|
|
| Lefgt fold on non-empty vectors
|
|
| foldl' :: Vector v b => (a -> b -> a) -> a -> v b -> a | Source |
|
| Left fold with strict accumulator
|
|
|
| Left fold on non-empty vectors with strict accumulator
|
|
|
| Right fold
|
|
|
| Right fold on non-empty vectors
|
|
| Specialised folds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Unfolding
|
|
|
|
| Scans
|
|
|
| Prefix scan
|
|
|
| Prefix scan with strict accumulator
|
|
|
| Suffix scan
|
|
|
| Suffix scan with strict accumulator
|
|
|
| Haskell-style scan
|
|
|
| Haskell-style scan with strict accumulator
|
|
|
| Scan over a non-empty vector
|
|
|
| Scan over a non-empty vector with a strict accumulator
|
|
| Enumeration
|
|
|
|
|
|
| Conversion to/from lists
|
|
|
| Convert a vector to a list
|
|
|
| Convert a list to a vector
|
|
| Conversion to/from Streams
|
|
|
| Convert a vector to a Stream
|
|
|
| Create a vector from a Stream
|
|
| MVector-based initialisation
|
|
|
| Construct a pure vector from a monadic initialiser
|
|
| Produced by Haddock version 2.4.2 |