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
- Unsafe functions
- Utility functions

Generic interface to pure vectors

- class IVector 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 :: IVector v a => v a -> Int
- null :: IVector v a => v a -> Bool
- empty :: IVector v a => v a
- singleton :: IVector v a => a -> v a
- cons :: IVector v a => a -> v a -> v a
- snoc :: IVector v a => v a -> a -> v a
- replicate :: IVector v a => Int -> a -> v a
- (++) :: IVector v a => v a -> v a -> v a
- copy :: IVector v a => v a -> v a
- (!) :: IVector v a => v a -> Int -> a
- head :: IVector v a => v a -> a
- last :: IVector v a => v a -> a
- indexM :: (IVector v a, Monad m) => v a -> Int -> m a
- headM :: (IVector v a, Monad m) => v a -> m a
- lastM :: (IVector v a, Monad m) => v a -> m a
- slice :: IVector v a => v a -> Int -> Int -> v a
- init :: IVector v a => v a -> v a
- tail :: IVector v a => v a -> v a
- take :: IVector v a => Int -> v a -> v a
- drop :: IVector v a => Int -> v a -> v a
- accum :: IVector v a => (a -> b -> a) -> v a -> [(Int, b)] -> v a
- (//) :: IVector v a => v a -> [(Int, a)] -> v a
- update :: (IVector v a, IVector v (Int, a)) => v a -> v (Int, a) -> v a
- backpermute :: (IVector v a, IVector v Int) => v a -> v Int -> v a
- reverse :: IVector v a => v a -> v a
- map :: (IVector v a, IVector v b) => (a -> b) -> v a -> v b
- concatMap :: (IVector v a, IVector v b) => (a -> v b) -> v a -> v b
- zipWith :: (IVector v a, IVector v b, IVector v c) => (a -> b -> c) -> v a -> v b -> v c
- zipWith3 :: (IVector v a, IVector v b, IVector v c, IVector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v d
- zip :: (IVector v a, IVector v b, IVector v (a, b)) => v a -> v b -> v (a, b)
- zip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c)
- unzip :: (IVector v a, IVector v b, IVector v (a, b)) => v (a, b) -> (v a, v b)
- unzip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c)
- eq :: (IVector v a, Eq a) => v a -> v a -> Bool
- cmp :: (IVector v a, Ord a) => v a -> v a -> Ordering
- filter :: IVector v a => (a -> Bool) -> v a -> v a
- takeWhile :: IVector v a => (a -> Bool) -> v a -> v a
- dropWhile :: IVector v a => (a -> Bool) -> v a -> v a
- elem :: (IVector v a, Eq a) => a -> v a -> Bool
- notElem :: (IVector v a, Eq a) => a -> v a -> Bool
- find :: IVector v a => (a -> Bool) -> v a -> Maybe a
- findIndex :: IVector v a => (a -> Bool) -> v a -> Maybe Int
- foldl :: IVector v b => (a -> b -> a) -> a -> v b -> a
- foldl1 :: IVector v a => (a -> a -> a) -> v a -> a
- foldl' :: IVector v b => (a -> b -> a) -> a -> v b -> a
- foldl1' :: IVector v a => (a -> a -> a) -> v a -> a
- foldr :: IVector v a => (a -> b -> b) -> b -> v a -> b
- foldr1 :: IVector v a => (a -> a -> a) -> v a -> a
- and :: IVector v Bool => v Bool -> Bool
- or :: IVector v Bool => v Bool -> Bool
- sum :: (IVector v a, Num a) => v a -> a
- product :: (IVector v a, Num a) => v a -> a
- maximum :: (IVector v a, Ord a) => v a -> a
- minimum :: (IVector v a, Ord a) => v a -> a
- unfoldr :: IVector v a => (b -> Maybe (a, b)) -> b -> v a
- prescanl :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v a
- prescanl' :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v a
- enumFromTo :: (IVector v a, Enum a) => a -> a -> v a
- enumFromThenTo :: (IVector v a, Enum a) => a -> a -> a -> v a
- toList :: IVector v a => v a -> [a]
- fromList :: IVector v a => [a] -> v a
- stream :: IVector v a => v a -> Stream a
- unstream :: IVector v a => Stream a -> v a
- new :: IVector 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 :: IVector v a => Int -> a -> v aSource

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

# Accessing individual elements

indexM :: (IVector 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 :: (IVector v a, IVector v b, IVector v c) => (a -> b -> c) -> v a -> v b -> v cSource

Zip two vectors with the given function.

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

Zip three vectors with the given function.

zip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c)Source

unzip3 :: (IVector v a, IVector v b, IVector v c, IVector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c)Source

# Comparisons

# Filtering

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

Drop elements which do not satisfy the predicate

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

Yield the longest prefix of elements satisfying the predicate.

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

Drop the longest prefix of elements that satisfy the predicate.

# Searching

# Folding

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

Left fold on non-empty vectors with strict accumulator

# Specialised folds

# Unfolding

# Scans

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

Prefix scan with strict accumulator

# Enumeration

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

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