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

Stability | experimental |

Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |

- Immutable vectors
- Length information
- Construction
- Accessing individual elements
- Subvectors
- Permutations
- Mapping
- Zipping and unzipping
- Comparisons
- Filtering
- Searching
- Folding
- Specialised folds
- Unfolding
- Scans
- Enumeration
- Conversion to/from lists
- Conversion to/from Streams
- MVector-based initialisation

Generic interface to pure vectors

- class Vector v a where
- vnew :: (forall mv m. MVector mv m a => m (mv a)) -> v a
- vlength :: v a -> Int
- unsafeSlice :: v a -> Int -> Int -> v a
- unsafeIndexM :: Monad m => v a -> Int -> m a

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

vnew :: (forall mv m. MVector mv m a => m (mv a)) -> v aSource

Construct a pure vector from a monadic initialiser (not fusible!)

Length of the vector (not fusible!)

unsafeSlice :: v a -> Int -> Int -> v aSource

Yield a part of the vector without copying it. No range checks!

unsafeIndexM :: Monad m => v a -> Int -> m aSource

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.

# Length information

# Construction

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

Vector of the given length with the given value in each position

# Accessing individual elements

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

Monadic indexing which can be strict in the vector while remaining lazy in the element.

# Subvectors

Yield a part of the vector without copying it. Safer version of
`unsafeSlice`

.

# Permutations

# Mapping

# Zipping and unzipping

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

Zip two vectors with the given function.

zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v dSource

Zip three vectors with the given function.

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)Source

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)Source

# Comparisons

# Filtering

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

Drop elements which do not satisfy the predicate

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

Yield the longest prefix of elements satisfying the predicate.

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

Drop the longest prefix of elements that satisfy the predicate.

# Searching

# Folding

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

Left fold on non-empty vectors with strict accumulator

# Specialised folds

# Unfolding

# Scans

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

Prefix scan with strict accumulator

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

Suffix scan with strict accumulator

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

Haskell-style scan with strict accumulator

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

Scan over a non-empty vector with a strict accumulator

# Enumeration

enumFromTo :: (Vector v a, Enum a) => a -> a -> v aSource

enumFromThenTo :: (Vector v a, Enum a) => a -> a -> a -> v aSource