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

Stability | experimental |

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

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
- unsafeIndex :: v a -> Int -> (a -> b) -> b

- length :: IVector v a => v a -> Int
- 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
- (!) :: IVector v a => v a -> Int -> a
- head :: IVector v a => v a -> a
- last :: IVector v a => v a -> a
- slice :: IVector v a => v a -> Int -> Int -> v a
- extract :: IVector v a => v a -> Int -> Int -> v a
- takeSlice :: IVector v a => Int -> v a -> v a
- take :: IVector v a => Int -> v a -> v a
- dropSlice :: IVector v a => Int -> v a -> v a
- drop :: IVector v a => Int -> v a -> 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
- bpermute :: (IVector v a, IVector v Int) => v a -> v Int -> v a
- map :: (IVector v a, IVector v b) => (a -> b) -> v a -> v b
- zipWith :: (IVector v a, IVector v b, IVector v c) => (a -> b -> c) -> v a -> v b -> v c
- zip :: (IVector v a, IVector v b, IVector v (a, b)) => v a -> v b -> v (a, b)
- 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
- takeWhileSlice :: IVector v a => (a -> Bool) -> v a -> v a
- takeWhile :: IVector v a => (a -> Bool) -> v a -> v a
- dropWhileSlice :: 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
- 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
- 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!

unsafeIndex :: v a -> Int -> (a -> b) -> bSource

Apply the given function to the element at the given position. This interface prevents us from being too lazy. 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 would be bad!

With `unsafeIndex`

, we can do

copy mv v ... = ... unsafeIndex v i (unsafeWrite mv i) ...

which does not have this problem.

# 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

# Subvectors

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

.

Copy `n`

elements starting at the given position to a new vector.

dropSlice :: IVector v a => Int -> v a -> v aSource

Yield all but the first `n`

elements without copying.

# Permutations

# Mapping and zipping

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.

# Comparisons

# Filtering

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

Drop elements which do not satisfy the predicate

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

Yield the longest prefix of elements satisfying the predicate without copying.

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

Copy the longest prefix of elements satisfying the predicate to a new vector

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

Drop the longest prefix of elements that satisfy the predicate without copying

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

Drop the longest prefix of elements that satisfy the predicate and copy the rest to a new vector.

# Searching

# Folding

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

Left fold on non-empty vectors with strict accumulator

# Scans

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

Prefix scan with strict accumulator