-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Size tagged vectors -- -- Please see README.md @package vector-sized @version 0.5.0.0 -- | This module reexports the functionality in Generic which maps -- well to explicity sized vectors. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Generic.Sized -- | A wrapper to tag vectors with a type level length. data Vector v (n :: Nat) a -- | O(1) Yield the length of the vector as an Int. length :: forall v n a. (KnownNat n) => Vector v n a -> Int -- | O(1) Yield the length of the vector as a Proxy. length' :: forall v n a. (KnownNat n) => Vector v n a -> Proxy n -- | O(1) Safe indexing using a Finite. index :: forall v n a. (KnownNat n, Vector v a) => Vector v n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v ((n + m) + 1) a -> Proxy n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall v n a. (KnownNat n, Vector v a) => Vector v n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall v n a. (Vector v a) => Vector v (n + 1) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall v n a. (Vector v a) => Vector v (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall v n k a m. (KnownNat n, KnownNat k, Vector v a, Monad m) => Vector v (n + k) a -> Proxy n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v (n + 1) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall v i n a. (KnownNat i, KnownNat n, Vector v a) => Proxy i -> Vector v (i + n) a -> Vector v n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall v i n a. (KnownNat i, KnownNat n, Vector v a) => Proxy i -> Proxy n -> Vector v (i + n) a -> Vector v n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall v n a. (Vector v a) => Vector v (n + 1) a -> Vector v n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall v n a. (Vector v a) => Vector v (n + 1) a -> Vector v n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (m + n) a -> Vector v n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Proxy n -> Vector v (m + n) a -> Vector v n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (m + n) a -> Vector v m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Proxy n -> Vector v (m + n) a -> Vector v m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (n + m) a -> (Vector v n a, Vector v m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Proxy n -> Vector v (n + m) a -> (Vector v n a, Vector v m a) -- | O(1) Empty vector. empty :: forall v a. (Vector v a) => Vector v 0 a -- | O(1) Vector with exactly one element. singleton :: forall v a. (Vector v a) => a -> Vector v 1 a -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall v n a. (KnownNat n, Vector v a) => a -> Vector v n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall v n a. (KnownNat n, Vector v a) => Proxy n -> a -> Vector v n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall v n a. (KnownNat n, Vector v a) => (Int -> a) -> Vector v n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall v n a. (KnownNat n, Vector v a) => Proxy n -> (Int -> a) -> Vector v n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generate_ :: forall v n a. (KnownNat n, Vector v a) => (Finite n -> a) -> Vector v n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall v n a. (KnownNat n, Vector v a) => (a -> a) -> a -> Vector v n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall v n a. (KnownNat n, Vector v a) => Proxy n -> (a -> a) -> a -> Vector v n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall v n m a. (KnownNat n, Vector v a, Monad m) => m a -> m (Vector v n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall v n m a. (KnownNat n, Vector v a, Monad m) => Proxy n -> m a -> m (Vector v n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall v n m a. (KnownNat n, Vector v a, Monad m) => (Int -> m a) -> m (Vector v n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall v n m a. (KnownNat n, Vector v a, Monad m) => Proxy n -> (Int -> m a) -> m (Vector v n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generateM_ :: forall v n m a. (KnownNat n, Vector v a, Monad m) => (Finite n -> m a) -> m (Vector v n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall v n a b. (KnownNat n, Vector v a) => (b -> (a, b)) -> b -> Vector v n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall v n a b. (KnownNat n, Vector v a) => Proxy n -> (b -> (a, b)) -> b -> Vector v n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> Vector v n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> Proxy n -> Vector v n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> a -> Vector v n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> a -> Proxy n -> Vector v n a -- | O(n) Prepend an element. cons :: forall v n a. Vector v a => a -> Vector v n a -> Vector v (n + 1) a -- | O(n) Append an element. snoc :: forall v n a. Vector v a => Vector v n a -> a -> Vector v (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall v n m a. Vector v a => Vector v n a -> Vector v m a -> Vector v (n + m) a -- | 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. force :: Vector v a => Vector v n a -> Vector v n 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> --(//) :: (Vector v a) => Vector v m a -> [(Int, a)] -> Vector v m 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> --update :: (Vector v a, Vector v (Int, a)) => Vector v m a -> Vector v n (Int, a) -> Vector v m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -> Vector v m a -- | Same as (//) but without bounds checking. unsafeUpd :: (Vector v a) => Vector v m a -> [(Int, a)] -> Vector v m a -- | Same as update but without bounds checking. unsafeUpdate :: (Vector v a, Vector v (Int, a)) => Vector v m a -> Vector v n (Int, a) -> Vector v m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -> Vector v m 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> --accum :: Vector v a => (a -> b -> a) -> Vector v m a -> [(Int, b)] -> Vector v m 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> --accumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> Vector v m a -> Vector v n (Int, b) -> Vector v m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> Vector v m a -> Vector v n Int -> Vector v n b -> Vector v m a -- | Same as accum but without bounds checking. unsafeAccum :: Vector v a => (a -> b -> a) -> Vector v m a -> [(Int, b)] -> Vector v m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> Vector v m a -> Vector v n (Int, b) -> Vector v m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> Vector v m a -> Vector v n Int -> Vector v n b -> Vector v m a -- | O(n) Reverse a vector reverse :: (Vector v a) => Vector v n a -> Vector v n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -- | O(n) Pair each element in a vector with its index indexed :: (Vector v a, Vector v (Int, a)) => Vector v n a -> Vector v n (Int, a) -- | O(n) Map a function over a vector map :: (Vector v a, Vector v b) => (a -> b) -> Vector v n a -> Vector v n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> Vector v n a -> Vector v n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (Vector v a, Vector v b) => (a -> Vector v m b) -> Vector v n a -> Vector v (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: (Monad m, Vector v a, Vector v b) => (a -> m b) -> Vector v n a -> m (Vector v n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: (Monad m, Vector v a, Vector v b) => (Int -> a -> m b) -> Vector v n a -> m (Vector v n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: (Monad m, Vector v a) => (a -> m b) -> Vector v n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: (Monad m, Vector v a) => (Int -> a -> m b) -> Vector v n a -> m () -- | 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, Vector v b) => Vector v n a -> (a -> m b) -> m (Vector v n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: (Monad m, Vector v a) => Vector v n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Vector v n a -> Vector v n b -> Vector v n c -- | Zip three vectors with the given function. zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d zipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (a -> b -> c -> d -> e) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e zipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => (a -> b -> c -> d -> e -> f) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f zipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => (a -> b -> c -> d -> e -> f -> g) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> c) -> Vector v n a -> Vector v n b -> Vector v n c izipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (Int -> a -> b -> c -> d) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d izipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (Int -> a -> b -> c -> d -> e) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e izipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f izipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n g -- | O(n) Zip two vectors of the same length zip :: (Vector v a, Vector v b, Vector v (a, b)) => Vector v n a -> Vector v n b -> Vector v n (a, b) zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n (a, b, c) zip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n (a, b, c, d) zip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n (a, b, c, d, e) zip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: (Monad m, Vector v a, Vector v b, Vector v c) => (a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: (Monad m, Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: (Monad m, Vector v a, Vector v b) => (a -> b -> m c) -> Vector v n a -> Vector v n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: (Monad m, Vector v a, Vector v b) => (Int -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: (Vector v a, Vector v b, Vector v (a, b)) => Vector v n (a, b) -> (Vector v n a, Vector v n b) unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Vector v n (a, b, c) -> (Vector v n a, Vector v n b, Vector v n c) unzip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Vector v n (a, b, c, d) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d) unzip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Vector v n (a, b, c, d, e) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e) unzip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Vector v n (a, b, c, d, e, f) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e, Vector v n f) -- | O(n) Check if the vector contains an element elem :: (Vector v a, Eq a) => a -> Vector v n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: (Vector v a, Eq a) => a -> Vector v n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: Vector v a => (a -> Bool) -> Vector v n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: Vector v a => (a -> Bool) -> Vector v n a -> Maybe Int -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Vector v a, Eq a) => a -> Vector v n a -> Maybe Int -- | O(n) Left fold foldl :: Vector v b => (a -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Left fold with strict accumulator foldl' :: Vector v b => (a -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Right fold foldr :: Vector v a => (a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: Vector v a => (a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: Vector v b => (a -> Int -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: Vector v b => (a -> Int -> b -> a) -> a -> Vector v n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: Vector v a => (Int -> a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Vector v a => (a -> Bool) -> Vector v n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Vector v a => (a -> Bool) -> Vector v n a -> Bool -- | O(n) Check if all elements are True and :: Vector v Bool => Vector v n Bool -> Bool -- | O(n) Check if any element is True or :: Vector v Bool => Vector v n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Vector v a, Num a) => Vector v n a -> a -- | O(n) Compute the produce of the elements product :: (Vector v a, Num a) => Vector v n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> Int -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> Int -- | O(n) Monadic fold foldM :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: (Monad m, Vector v b) => (a -> Int -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: (Monad m, Vector v b) => (a -> Int -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: (Monad m, Vector v b) => (a -> Int -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: (Monad m, Vector v b) => (a -> Int -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: (Monad m, Vector v a, Vector v (m a)) => Vector v n (m a) -> m (Vector v n a) -- | Evaluate each action and discard the results sequence_ :: (Monad m, Vector v (m a)) => Vector v n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Prescan with strict accumulator prescanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan with strict accumulator postscanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Haskell-style scan scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan over a non-empty vector scanl1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan postscanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left Haskell-style scan scanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Convert a vector to a list toList :: Vector v a => Vector v n a -> [a] -- | O(n) Convert a list to a vector fromList :: (Vector v a, KnownNat n) => [a] -> Maybe (Vector v n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall v n a. (Vector v a, KnownNat n) => [a] -> Maybe (Vector v n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall v n a. (Vector v a, KnownNat n) => Proxy n -> [a] -> Maybe (Vector v n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall v a r. Vector v a => [a] -> (forall n. KnownNat n => Vector v n a -> r) -> r -- | O(n) Convert different vector types convert :: (Vector v a, Vector w a) => Vector v n a -> Vector w n a -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall v n a. (Vector v a, KnownNat n) => v a -> Maybe (Vector v n a) -- | Takes a Vector and returns a continuation providing a -- Sized with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall v a r. Vector v a => v a -> (forall n. KnownNat n => Vector v n a -> r) -> r fromSized :: Vector v n a -> v a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: forall a b v w (n :: Nat). (Vector v a, Vector w b) => (v a -> w b) -> Vector v n a -> Vector w n b instance (Data.Data.Data (v a), Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable v, GHC.TypeLits.KnownNat n) => Data.Data.Data (Data.Vector.Generic.Sized.Vector v n a) instance GHC.Generics.Generic (Data.Vector.Generic.Sized.Vector v n a) instance Control.DeepSeq.NFData (v a) => Control.DeepSeq.NFData (Data.Vector.Generic.Sized.Vector v n a) instance Data.Traversable.Traversable v => Data.Traversable.Traversable (Data.Vector.Generic.Sized.Vector v n) instance Data.Foldable.Foldable v => Data.Foldable.Foldable (Data.Vector.Generic.Sized.Vector v n) instance GHC.Base.Functor v => GHC.Base.Functor (Data.Vector.Generic.Sized.Vector v n) instance GHC.Classes.Ord (v a) => GHC.Classes.Ord (Data.Vector.Generic.Sized.Vector v n a) instance GHC.Classes.Eq (v a) => GHC.Classes.Eq (Data.Vector.Generic.Sized.Vector v n a) instance GHC.Show.Show (v a) => GHC.Show.Show (Data.Vector.Generic.Sized.Vector v n a) instance (GHC.TypeLits.KnownNat n, Foreign.Storable.Storable a, Data.Vector.Generic.Base.Vector v a) => Foreign.Storable.Storable (Data.Vector.Generic.Sized.Vector v n a) instance GHC.TypeLits.KnownNat n => GHC.Base.Applicative (Data.Vector.Generic.Sized.Vector Data.Vector.Vector n) instance (GHC.Base.Monoid m, Data.Vector.Generic.Base.Vector v m, GHC.TypeLits.KnownNat n) => GHC.Base.Monoid (Data.Vector.Generic.Sized.Vector v n m) instance Data.Vector.Generic.Base.Vector v m => GHC.Base.Monoid (Data.Vector.Generic.Sized.Vector v 0 m) -- | This module re-exports the functionality in Sized specialized -- to Storable -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Storable.Sized -- | Vector specialized to use Storable type Vector = Vector Vector -- | O(1) Yield the length of the vector as an Int. length :: forall n a. (KnownNat n) => Vector n a -> Int -- | O(1) Yield the length of the vector as a Proxy. length' :: forall n a. (KnownNat n) => Vector n a -> Proxy n -- | O(1) Safe indexing using a Finite. index :: forall n a. (KnownNat n, Storable a) => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector ((n + m) + 1) a -> Proxy n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. (KnownNat n, Storable a) => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. (Storable a) => Vector (n + 1) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. (Storable a) => Vector (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall n k a m. (KnownNat n, KnownNat k, Storable a, Monad m) => Vector (n + k) a -> Proxy n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall i n a. (KnownNat i, KnownNat n, Storable a) => Proxy i -> Vector (i + n) a -> Vector n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall i n a. (KnownNat i, KnownNat n, Storable a) => Proxy i -> Proxy n -> Vector (i + n) a -> Vector n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall n a. (Storable a) => Vector (n + 1) a -> Vector n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall n a. (Storable a) => Vector (n + 1) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (m + n) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Proxy n -> Vector (m + n) a -> Vector n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (m + n) a -> Vector m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Proxy n -> Vector (m + n) a -> Vector m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Proxy n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. (Storable a) => Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. (Storable a) => a -> Vector 1 a -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall n a. (KnownNat n, Storable a) => a -> Vector n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall n a. (KnownNat n, Storable a) => Proxy n -> a -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall n a. (KnownNat n, Storable a) => (Int -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall n a. (KnownNat n, Storable a) => Proxy n -> (Int -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generate_ :: forall n a. (KnownNat n, Storable a) => (Finite n -> a) -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall n a. (KnownNat n, Storable a) => (a -> a) -> a -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall n a. (KnownNat n, Storable a) => Proxy n -> (a -> a) -> a -> Vector n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall n m a. (KnownNat n, Storable a, Monad m) => m a -> m (Vector n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall n m a. (KnownNat n, Storable a, Monad m) => Proxy n -> m a -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall n m a. (KnownNat n, Storable a, Monad m) => (Int -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall n m a. (KnownNat n, Storable a, Monad m) => Proxy n -> (Int -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generateM_ :: forall n m a. (KnownNat n, Storable a, Monad m) => (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall n a b. (KnownNat n, Storable a) => (b -> (a, b)) -> b -> Vector n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall n a b. (KnownNat n, Storable a) => Proxy n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall n a. (KnownNat n, Storable a, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall n a. (KnownNat n, Storable a, Num a) => a -> Proxy n -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Storable a, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall n a. (KnownNat n, Storable a, Num a) => a -> a -> Proxy n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. Storable a => a -> Vector n a -> Vector (n + 1) a -- | O(n) Append an element. snoc :: forall n a. Storable a => Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Storable a => Vector n a -> Vector m a -> Vector (n + m) a -- | 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. force :: Storable a => Vector n a -> Vector n 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> --(//) :: (Storable a) => Vector m a -> [(Int, a)] -> Vector m 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> --update :: (Storable a, Storable (Int, a)) => Vector m a -> Vector n (Int, a) -> Vector m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: Storable a => Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: (Storable a) => Vector m a -> [(Int, a)] -> Vector m a -- | Same as update but without bounds checking. unsafeUpdate :: (Storable a, Storable (Int, a)) => Vector m a -> Vector n (Int, a) -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Storable a => Vector m a -> Vector n Int -> Vector n a -> Vector m 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> --accum :: Storable a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m 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> --accumulate :: (Storable a, Storable (Int, b)) => (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: Storable a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (Storable a, Storable (Int, b)) => (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector reverse :: (Storable a) => Vector n a -> Vector n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: Storable a => Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Storable a => Vector m a -> Vector n Int -> Vector n a -- | O(n) Pair each element in a vector with its index indexed :: (Storable a, Storable (Int, a)) => Vector n a -> Vector n (Int, a) -- | O(n) Map a function over a vector map :: (Storable a, Storable b) => (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Storable a, Storable b) => (Int -> a -> b) -> Vector n a -> Vector n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (Storable a, Storable b) => (a -> Vector m b) -> Vector n a -> Vector (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: (Monad m, Storable a, Storable b) => (a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: (Monad m, Storable a, Storable b) => (Int -> a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: (Monad m, Storable a) => (a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: (Monad m, Storable a) => (Int -> a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results. Equvalent to flip mapM. forM :: (Monad m, Storable a, Storable b) => Vector n a -> (a -> m b) -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: (Monad m, Storable a) => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f zipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => (a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Storable a, Storable b, Storable c) => (Int -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (Int -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (Int -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f izipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length zip :: (Storable a, Storable b, Storable (a, b)) => Vector n a -> Vector n b -> Vector n (a, b) zip3 :: (Storable a, Storable b, Storable c, Storable (a, b, c)) => Vector n a -> Vector n b -> Vector n c -> Vector n (a, b, c) zip4 :: (Storable a, Storable b, Storable c, Storable d, Storable (a, b, c, d)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n (a, b, c, d) zip5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable (a, b, c, d, e)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n (a, b, c, d, e) zip6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable (a, b, c, d, e, f)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: (Monad m, Storable a, Storable b, Storable c) => (a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: (Monad m, Storable a, Storable b, Storable c) => (Int -> a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: (Monad m, Storable a, Storable b) => (a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: (Monad m, Storable a, Storable b) => (Int -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: (Storable a, Storable b, Storable (a, b)) => Vector n (a, b) -> (Vector n a, Vector n b) unzip3 :: (Storable a, Storable b, Storable c, Storable (a, b, c)) => Vector n (a, b, c) -> (Vector n a, Vector n b, Vector n c) unzip4 :: (Storable a, Storable b, Storable c, Storable d, Storable (a, b, c, d)) => Vector n (a, b, c, d) -> (Vector n a, Vector n b, Vector n c, Vector n d) unzip5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable (a, b, c, d, e)) => Vector n (a, b, c, d, e) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e) unzip6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable (a, b, c, d, e, f)) => Vector n (a, b, c, d, e, f) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e, Vector n f) -- | O(n) Check if the vector contains an element elem :: (Storable a, Eq a) => a -> Vector n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: (Storable a, Eq a) => a -> Vector n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: Storable a => (a -> Bool) -> Vector n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: Storable a => (a -> Bool) -> Vector n a -> Maybe Int -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Storable a, Eq a) => a -> Vector n a -> Maybe Int -- | O(n) Left fold foldl :: Storable b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold with strict accumulator foldl' :: Storable b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold foldr :: Storable a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: Storable a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: Storable b => (a -> Int -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: Storable b => (a -> Int -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: Storable a => (Int -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: Storable a => (Int -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Storable a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Storable a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if all elements are True and :: Vector n Bool -> Bool -- | O(n) Check if any element is True or :: Vector n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Storable a, Num a) => Vector n a -> a -- | O(n) Compute the produce of the elements product :: (Storable a, Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> Int -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> Int -- | O(n) Monadic fold foldM :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: (Monad m, Storable b) => (a -> Int -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: (Monad m, Storable b) => (a -> Int -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: (Monad m, Storable b) => (a -> Int -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: (Monad m, Storable b) => (a -> Int -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: (Monad m, Storable a, Storable (m a)) => Vector n (m a) -> m (Vector n a) -- | Evaluate each action and discard the results sequence_ :: (Monad m, Storable (m a)) => Vector n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan over a non-empty vector scanl1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan postscanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan scanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Convert a vector to a list toList :: Storable a => Vector n a -> [a] -- | O(n) Convert a list to a vector fromList :: (Storable a, KnownNat n) => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall n a. (Storable a, KnownNat n) => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a. (Storable a, KnownNat n) => Proxy n -> [a] -> Maybe (Vector n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall a r. Storable a => [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall n a. (Storable a, KnownNat n) => Vector a -> Maybe (Vector n a) -- | Takes a Vector and returns a continuation providing a -- Vector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall a r. Storable a => Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r fromSized :: Vector n a -> Vector a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: forall a b (n :: Nat). (Storable a, Storable b) => (Vector a -> Vector b) -> Vector n a -> Vector n b -- | This module re-exports the functionality in Sized specialized -- to Vector. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Sized -- | Vector specialized to use Vector type Vector = Vector Vector -- | O(1) Yield the length of the vector as an Int. length :: forall n a. KnownNat n => Vector n a -> Int -- | O(1) Yield the length of the vector as a Proxy. length' :: forall n a. KnownNat n => Vector n a -> Proxy n -- | O(1) Safe indexing using a Finite. index :: forall n a. KnownNat n => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a. (KnownNat n, KnownNat m) => Vector ((n + m) + 1) a -> Proxy n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. KnownNat n => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. Vector (n + 1) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. Vector (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall n a m. (KnownNat n, Monad m) => Vector n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall n k a m. (KnownNat n, KnownNat k, Monad m) => Vector (n + k) a -> Proxy n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall n a m. (KnownNat n, Monad m) => Vector n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall n a m. (KnownNat n, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall n a m. (KnownNat n, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall i n a. (KnownNat i, KnownNat n) => Proxy i -> Vector (i + n) a -> Vector n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall i n a. (KnownNat i, KnownNat n) => Proxy i -> Proxy n -> Vector (i + n) a -> Vector n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall n a. Vector (n + 1) a -> Vector n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall n a. Vector (n + 1) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n m a. (KnownNat n, KnownNat m) => Vector (m + n) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n m a. (KnownNat n, KnownNat m) => Proxy n -> Vector (m + n) a -> Vector n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n m a. (KnownNat n, KnownNat m) => Vector (m + n) a -> Vector m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n m a. (KnownNat n, KnownNat m) => Proxy n -> Vector (m + n) a -> Vector m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m a. (KnownNat n, KnownNat m) => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a. (KnownNat n, KnownNat m) => Proxy n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. a -> Vector 1 a -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall n a. KnownNat n => a -> Vector n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall n a. KnownNat n => Proxy n -> a -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall n a. KnownNat n => (Int -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall n a. KnownNat n => Proxy n -> (Int -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generate_ :: forall n a. KnownNat n => (Finite n -> a) -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall n a. KnownNat n => (a -> a) -> a -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall n a. KnownNat n => Proxy n -> (a -> a) -> a -> Vector n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall n m a. (KnownNat n, Monad m) => m a -> m (Vector n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall n m a. (KnownNat n, Monad m) => Proxy n -> m a -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall n m a. (KnownNat n, Monad m) => (Int -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall n m a. (KnownNat n, Monad m) => Proxy n -> (Int -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. -- -- The function can expect a Finite n, meaning that its -- input will always be between 0 and n - 1. generateM_ :: forall n m a. (KnownNat n, Monad m) => (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall n a b. KnownNat n => (b -> (a, b)) -> b -> Vector n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall n a b. KnownNat n => Proxy n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall n a. (KnownNat n, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall n a. (KnownNat n, Num a) => a -> Proxy n -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall n a. (KnownNat n, Num a) => a -> a -> Proxy n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. a -> Vector n a -> Vector (n + 1) a -- | O(n) Append an element. snoc :: forall n a. Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Vector n a -> Vector m a -> Vector (n + m) a -- | 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. force :: Vector n a -> Vector n 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> --(//) :: Vector m a -> [(Int, a)] -> Vector m 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> --update :: Vector m a -> Vector n (Int, a) -> Vector m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: Vector m a -> [(Int, a)] -> Vector m a -- | Same as update but without bounds checking. unsafeUpdate :: Vector m a -> Vector n (Int, a) -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Vector m a -> Vector n Int -> Vector n a -> Vector m 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> --accum :: (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m 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> --accumulate :: (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | O(m+n) 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> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector reverse :: Vector n a -> Vector n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Vector m a -> Vector n Int -> Vector n a -- | O(n) Pair each element in a vector with its index indexed :: Vector n a -> Vector n (Int, a) -- | O(n) Map a function over a vector map :: (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Int -> a -> b) -> Vector n a -> Vector n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (a -> Vector m b) -> Vector n a -> Vector (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: Monad m => (a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: Monad m => (Int -> a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: Monad m => (a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: Monad m => (Int -> a -> m b) -> Vector n a -> m () -- | 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 n a -> (a -> m b) -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: Monad m => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Int -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Int -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Int -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Int -> a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f izipWith6 :: (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length zip :: Vector n a -> Vector n b -> Vector n (a, b) zip3 :: Vector n a -> Vector n b -> Vector n c -> Vector n (a, b, c) zip4 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n (a, b, c, d) zip5 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n (a, b, c, d, e) zip6 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: Monad m => (a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: Monad m => (Int -> a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: Monad m => (a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: Monad m => (Int -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: Vector n (a, b) -> (Vector n a, Vector n b) unzip3 :: Vector n (a, b, c) -> (Vector n a, Vector n b, Vector n c) unzip4 :: Vector n (a, b, c, d) -> (Vector n a, Vector n b, Vector n c, Vector n d) unzip5 :: Vector n (a, b, c, d, e) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e) unzip6 :: Vector n (a, b, c, d, e, f) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e, Vector n f) -- | O(n) Check if the vector contains an element elem :: Eq a => a -> Vector n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: Eq a => a -> Vector n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: (a -> Bool) -> Vector n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: (a -> Bool) -> Vector n a -> Maybe Int -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Eq a) => a -> Vector n a -> Maybe Int -- | O(n) Left fold foldl :: (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold with strict accumulator foldl' :: (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold foldr :: (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: (a -> Int -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: (a -> Int -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: (Int -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: (Int -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if all elements are True and :: Vector n Bool -> Bool -- | O(n) Check if any element is True or :: Vector n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Num a) => Vector n a -> a -- | O(n) Compute the produce of the elements product :: (Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Ord a, KnownNat n) => Vector (n + 1) a -> Int -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Ord a, KnownNat n) => Vector (n + 1) a -> Int -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> Int -- | O(n) Monadic fold foldM :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: Monad m => (a -> Int -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: Monad m => (a -> Int -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: Monad m => (a -> Int -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: Monad m => (a -> Int -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: Monad m => Vector n (m a) -> m (Vector n a) -- | Evaluate each action and discard the results sequence_ :: Monad m => Vector n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator prescanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan postscanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator postscanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan scanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan over a non-empty vector scanl1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan postscanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan scanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Convert a vector to a list toList :: Vector n a -> [a] -- | O(n) Convert a list to a vector fromList :: KnownNat n => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall n a. KnownNat n => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a. KnownNat n => Proxy n -> [a] -> Maybe (Vector n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall a r. [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall n a. KnownNat n => Vector a -> Maybe (Vector n a) -- | Takes a Vector and returns a continuation providing a -- Vector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall a r. Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r fromSized :: Vector n a -> Vector a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: (Vector a -> Vector b) -> Vector n a -> Vector n b