-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient Arrays -- -- An efficient implementation of Int-indexed arrays (both mutable and -- immutable), with a powerful loop fusion optimization framework . -- -- It is structured as follows: -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: Int -> [a] -> Stream a unsafeFromList :: Size -> [a] -> Stream a -- | Convert a pure stream to a monadic stream liftStream :: (Monad m) => Stream a -> Stream m a -- | Apply a monadic action to each element of the stream, producing a -- monadic stream of results mapM :: (Monad m) => (a -> m b) -> Stream a -> Stream m b -- | Apply a monadic action to each element of the stream mapM_ :: (Monad m) => (a -> m b) -> Stream a -> m () zipWithM :: (Monad m) => (a -> b -> m c) -> Stream a -> Stream b -> Stream m c zipWithM_ :: (Monad m) => (a -> b -> m c) -> Stream a -> Stream b -> m () -- | Yield a monadic stream of elements that satisfy the monadic predicate filterM :: (Monad m) => (a -> m Bool) -> Stream a -> Stream m a -- | Monadic fold foldM :: (Monad m) => (a -> b -> m a) -> a -> Stream b -> m a -- | Monadic fold over non-empty stream fold1M :: (Monad m) => (a -> a -> m a) -> Stream a -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m) => (a -> b -> m a) -> a -> Stream b -> m a -- | Monad fold over non-empty stream with strict accumulator fold1M' :: (Monad m) => (a -> a -> m a) -> Stream a -> m a -- | Check if two Streams are equal eq :: (Eq a) => Stream a -> Stream a -> Bool -- | Lexicographically compare two Streams cmp :: (Ord a) => Stream a -> Stream a -> Ordering instance (Ord a) => Ord (Stream Id a) instance (Eq a) => Eq (Stream Id a) -- | Generic interface to mutable vectors module Data.Vector.Generic.Mutable -- | Class of mutable vectors parametrised with a primitive state token. class MVector v a basicLength :: (MVector v a) => v s a -> Int basicUnsafeSlice :: (MVector v a) => Int -> Int -> v s a -> v s a basicOverlaps :: (MVector v a) => v s a -> v s a -> Bool basicUnsafeNew :: (MVector v a, PrimMonad m) => Int -> m (v (PrimState m) a) basicUnsafeNewWith :: (MVector v a, PrimMonad m) => Int -> a -> m (v (PrimState m) a) basicUnsafeRead :: (MVector v a, PrimMonad m) => v (PrimState m) a -> Int -> m a basicUnsafeWrite :: (MVector v a, PrimMonad m) => v (PrimState m) a -> Int -> a -> m () basicClear :: (MVector v a, PrimMonad m) => v (PrimState m) a -> m () basicSet :: (MVector v a, PrimMonad m) => v (PrimState m) a -> a -> m () basicUnsafeCopy :: (MVector v a, PrimMonad m) => v (PrimState m) a -> v (PrimState m) a -> m () basicUnsafeGrow :: (MVector v a, PrimMonad m) => v (PrimState m) a -> Int -> m (v (PrimState m) a) -- | Length of the mutable vector. length :: (MVector v a) => v s a -> Int overlaps :: (MVector v a) => v s a -> v s a -> Bool -- | Create a mutable vector of the given length. new :: (PrimMonad m, MVector v a) => Int -> m (v (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. newWith :: (PrimMonad m, MVector v a) => Int -> a -> m (v (PrimState m) a) -- | Yield the element at the given position. read :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m a -- | Replace the element at the given position. write :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> Int -> m () -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (PrimMonad m, MVector v a) => v (PrimState m) a -> m () -- | Set all elements of the vector to the given value. set :: (PrimMonad m, MVector v a) => v (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (PrimMonad m, MVector v a) => v (PrimState m) a -> v (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive. grow :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m (v (PrimState m) a) -- | Yield a part of the mutable vector without copying it. slice :: (MVector v a) => Int -> Int -> v s a -> v s a take :: (MVector v a) => Int -> v s a -> v s a drop :: (MVector v a) => Int -> v s a -> v s a init :: (MVector v a) => v s a -> v s a tail :: (MVector v a) => v s a -> v s a -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: (MVector v a) => Int -> Int -> v s a -> v s a unsafeInit :: (MVector v a) => v s a -> v s a unsafeTail :: (MVector v a) => v s a -> v s a -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (PrimMonad m, MVector v a) => Int -> m (v (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. The length is not checked. unsafeNewWith :: (PrimMonad m, MVector v a) => Int -> a -> m (v (PrimState m) a) -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. No bounds checks are -- performed. unsafeSwap :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> Int -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (PrimMonad m, MVector v a) => v (PrimState m) a -> v (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive but this is not checked. unsafeGrow :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m (v (PrimState m) a) -- | Create a new mutable vector and fill it with elements from the -- Stream. The vector will grow exponentially if the maximum size -- of the Stream is unknown. unstream :: (PrimMonad m, MVector v a) => Stream a -> m (v (PrimState m) a) -- | Create a new mutable vector and fill it with elements from the -- Stream from right to left. The vector will grow exponentially -- if the maximum size of the Stream is unknown. unstreamR :: (PrimMonad m, MVector v a) => Stream a -> m (v (PrimState m) a) -- | Create a new mutable vector and fill it with elements from the monadic -- stream. The vector will grow exponentially if the maximum size of the -- stream is unknown. munstream :: (PrimMonad m, MVector v a) => MStream m a -> m (v (PrimState m) a) -- | Create a new mutable vector and fill it with elements from the monadic -- stream from right to left. The vector will grow exponentially if the -- maximum size of the stream is unknown. munstreamR :: (PrimMonad m, MVector v a) => MStream m a -> m (v (PrimState m) a) transform :: (PrimMonad m, MVector v a) => (MStream m a -> MStream m a) -> v (PrimState m) a -> m (v (PrimState m) a) transformR :: (PrimMonad m, MVector v a) => (MStream m a -> MStream m a) -> v (PrimState m) a -> m (v (PrimState m) a) fill :: (PrimMonad m, MVector v a) => v (PrimState m) a -> MStream m a -> m (v (PrimState m) a) fillR :: (PrimMonad m, MVector v a) => v (PrimState m) a -> MStream m a -> m (v (PrimState m) a) unsafeAccum :: (PrimMonad m, MVector v a) => (a -> b -> a) -> v (PrimState m) a -> Stream (Int, b) -> m () accum :: (PrimMonad m, MVector v a) => (a -> b -> a) -> v (PrimState m) a -> Stream (Int, b) -> m () unsafeUpdate :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Stream (Int, a) -> m () update :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Stream (Int, a) -> m () reverse :: (PrimMonad m, MVector v a) => v (PrimState m) a -> m () unstablePartition :: (PrimMonad m, MVector v a) => (a -> Bool) -> v (PrimState m) a -> m Int unstablePartitionStream :: (PrimMonad m, MVector v a) => (a -> Bool) -> Stream a -> m (v (PrimState m) a, v (PrimState m) a) partitionStream :: (PrimMonad m, MVector v a) => (a -> Bool) -> Stream a -> m (v (PrimState m) a, v (PrimState m) a) -- | Class of pure vectors module Data.Vector.Generic.Base -- | Class of immutable vectors. class (MVector (Mutable v) a) => Vector v a unsafeFreeze :: (Vector v a, PrimMonad m) => Mutable v (PrimState m) a -> m (v a) basicLength :: (Vector v a) => v a -> Int basicUnsafeSlice :: (Vector v a) => Int -> Int -> v a -> v a basicUnsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a basicUnsafeCopy :: (Vector v a, PrimMonad m) => Mutable v (PrimState m) a -> v a -> m () elemseq :: (Vector v a) => v a -> a -> b -> b -- | Mutable v s a is the mutable version of the pure vector type -- v a with the state token s -- | Purely functional interface to initialisation of mutable vectors module Data.Vector.Generic.New data New v a New :: (forall s. ST s (Mutable v s a)) -> New v a create :: (forall s. ST s (Mutable v s a)) -> New v a run :: New v a -> ST s (Mutable v s a) apply :: (forall s. Mutable v s a -> Mutable v s a) -> New v a -> New v a modify :: (forall s. Mutable v s a -> ST s ()) -> New v a -> New v a modifyWithStream :: (forall s. Mutable v s a -> Stream b -> ST s ()) -> New v a -> Stream b -> New v a unstream :: (Vector v a) => Stream a -> New v a transform :: (Vector v a) => (forall m. (Monad m) => MStream m a -> MStream m a) -> New v a -> New v a unstreamR :: (Vector v a) => Stream a -> New v a transformR :: (Vector v a) => (forall m. (Monad m) => MStream m a -> MStream m a) -> New v a -> New v a slice :: (Vector v a) => Int -> Int -> New v a -> New v a init :: (Vector v a) => New v a -> New v a tail :: (Vector v a) => New v a -> New v a take :: (Vector v a) => Int -> New v a -> New v a drop :: (Vector v a) => Int -> New v a -> New v a unsafeSlice :: (Vector v a) => Int -> Int -> New v a -> New v a unsafeInit :: (Vector v a) => New v a -> New v a unsafeTail :: (Vector v a) => New v a -> New v a -- | Generic interface to pure vectors module Data.Vector.Generic -- | Class of immutable vectors. class (MVector (Mutable v) a) => Vector v a unsafeFreeze :: (Vector v a, PrimMonad m) => Mutable v (PrimState m) a -> m (v a) basicLength :: (Vector v a) => v a -> Int basicUnsafeSlice :: (Vector v a) => Int -> Int -> v a -> v a basicUnsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a basicUnsafeCopy :: (Vector v a, PrimMonad m) => Mutable v (PrimState m) a -> v a -> m () elemseq :: (Vector v a) => v a -> a -> b -> b -- | Mutable v s a is the mutable version of the pure vector type -- v a with the state token s length :: (Vector v a) => v a -> Int null :: (Vector v a) => v a -> Bool -- | Empty vector empty :: (Vector v a) => v a -- | Vector with exaclty one element singleton :: (Vector v a) => a -> v a -- | Prepend an element cons :: (Vector v a) => a -> v a -> v a -- | Append an element snoc :: (Vector v a) => v a -> a -> v a -- | Vector of the given length with the given value in each position replicate :: (Vector v a) => Int -> a -> v a -- | Generate a vector of the given length by applying the function to each -- index generate :: (Vector v a) => Int -> (Int -> a) -> v a -- | Concatenate two vectors (++) :: (Vector v a) => v a -> v a -> v a -- | Create a copy of a vector. Useful when dealing with slices. force :: (Vector v a) => v a -> v a -- | Indexing (!) :: (Vector v a) => v a -> Int -> a -- | First element head :: (Vector v a) => v a -> a -- | Last element last :: (Vector v a) => v a -> a -- | Monadic indexing which can be strict in the vector while remaining -- lazy in the element. indexM :: (Vector v a, Monad m) => v a -> Int -> m a headM :: (Vector v a, Monad m) => v a -> m a lastM :: (Vector v a, Monad m) => v a -> m a -- | Unsafe indexing without bounds checking unsafeIndex :: (Vector v a) => v a -> Int -> a -- | Yield the first element of a vector without checking if the vector is -- empty unsafeHead :: (Vector v a) => v a -> a -- | Yield the last element of a vector without checking if the vector is -- empty unsafeLast :: (Vector v a) => v a -> a -- | Unsafe monadic indexing without bounds checks unsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a unsafeHeadM :: (Vector v a, Monad m) => v a -> m a unsafeLastM :: (Vector v a, Monad m) => v a -> m a -- | Yield a part of the vector without copying it. slice :: (Vector v a) => Int -> Int -> v a -> v a -- | Yield all but the last element without copying. init :: (Vector v a) => v a -> v a -- | All but the first element (without copying). tail :: (Vector v a) => v a -> v a -- | Yield the first n elements without copying. take :: (Vector v a) => Int -> v a -> v a -- | Yield all but the first n elements without copying. drop :: (Vector v a) => Int -> v a -> v a -- | Unsafely yield a part of the vector without copying it and without -- performing bounds checks. unsafeSlice :: (Vector v a) => Int -> Int -> v a -> v a unsafeInit :: (Vector v a) => v a -> v a unsafeTail :: (Vector v a) => v a -> v a unsafeTake :: (Vector v a) => Int -> v a -> v a unsafeDrop :: (Vector v a) => Int -> v a -> v a accum :: (Vector v a) => (a -> b -> a) -> v a -> [(Int, b)] -> v a accumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> v a -> v (Int, b) -> v a accumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> v a -> v Int -> v b -> v a (//) :: (Vector v a) => v a -> [(Int, a)] -> v a update :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a update_ :: (Vector v a, Vector v Int) => v a -> v Int -> v a -> v a backpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a reverse :: (Vector v a) => v a -> v a unsafeAccum :: (Vector v a) => (a -> b -> a) -> v a -> [(Int, b)] -> v a unsafeAccumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> v a -> v (Int, b) -> v a unsafeAccumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> v a -> v Int -> v b -> v a unsafeUpd :: (Vector v a) => v a -> [(Int, a)] -> v a unsafeUpdate :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a unsafeUpdate_ :: (Vector v a, Vector v Int) => v a -> v Int -> v a -> v a unsafeBackpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a -- | Map a function over a vector map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b -- | Apply a function to every index/value pair imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b concatMap :: (Vector v a, Vector v b) => (a -> v b) -> v a -> v b -- | Zip two vectors with the given function. zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v 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) -> v a -> v b -> v c -> v d zipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (a -> b -> c -> d -> e) -> v a -> v b -> v c -> v d -> v 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) -> v a -> v b -> v c -> v d -> v e -> v 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) -> v a -> v b -> v c -> v d -> v e -> v f -> v g -- | Zip two vectors and their indices with the given function. izipWith :: (Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> c) -> v a -> v b -> v c -- | Zip three vectors and their indices with the given function. izipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (Int -> a -> b -> c -> d) -> v a -> v b -> v c -> v d izipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (Int -> a -> b -> c -> d -> e) -> v a -> v b -> v c -> v d -> v 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) -> v a -> v b -> v c -> v d -> v e -> v 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) -> v a -> v b -> v c -> v d -> v e -> v f -> v g zip :: (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c) zip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => v a -> v b -> v c -> v d -> v (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)) => v a -> v b -> v c -> v d -> v e -> v (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)) => v a -> v b -> v c -> v d -> v e -> v f -> v (a, b, c, d, e, f) unzip :: (Vector v a, Vector v b, Vector v (a, b)) => v (a, b) -> (v a, v b) unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c) unzip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => v (a, b, c, d) -> (v a, v b, v c, v d) unzip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => v (a, b, c, d, e) -> (v a, v b, v c, v d, v 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)) => v (a, b, c, d, e, f) -> (v a, v b, v c, v d, v e, v f) eq :: (Vector v a, Eq a) => v a -> v a -> Bool cmp :: (Vector v a, Ord a) => v a -> v a -> Ordering -- | Drop elements that do not satisfy the predicate filter :: (Vector v a) => (a -> Bool) -> v a -> v a -- | Drop elements that do not satisfy the predicate (applied to values and -- their indices) ifilter :: (Vector v a) => (Int -> a -> Bool) -> v a -> v a -- | Yield the longest prefix of elements satisfying the predicate. takeWhile :: (Vector v a) => (a -> Bool) -> v a -> v a -- | Drop the longest prefix of elements that satisfy the predicate. dropWhile :: (Vector v a) => (a -> Bool) -> v a -> v a -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- relative order of the elements is preserved at the cost of a -- (sometimes) reduced performance compared to unstablePartition. partition :: (Vector v a) => (a -> Bool) -> v a -> (v a, v a) -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- order of the elements is not preserved but the operation is often -- faster than partition. unstablePartition :: (Vector v a) => (a -> Bool) -> v a -> (v a, v a) -- | Split the vector into the longest prefix of elements that satisfy the -- predicate and the rest. span :: (Vector v a) => (a -> Bool) -> v a -> (v a, v a) -- | Split the vector into the longest prefix of elements that do not -- satisfy the predicate and the rest. break :: (Vector v a) => (a -> Bool) -> v a -> (v a, v a) -- | Check whether the vector contains an element elem :: (Vector v a, Eq a) => a -> v a -> Bool -- | Inverse of elem notElem :: (Vector v a, Eq a) => a -> v a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (Vector v a) => (a -> Bool) -> v a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (Vector v a) => (a -> Bool) -> v a -> Maybe Int -- | Yield the indices of elements satisfying the predicate findIndices :: (Vector v a, Vector v Int) => (a -> Bool) -> v a -> v Int -- | Yield Just the index of the first occurence of the given -- element or Nothing if the vector does not contain the element elemIndex :: (Vector v a, Eq a) => a -> v a -> Maybe Int -- | Yield the indices of all occurences of the given element elemIndices :: (Vector v a, Vector v Int, Eq a) => a -> v a -> v Int -- | Left fold foldl :: (Vector v b) => (a -> b -> a) -> a -> v b -> a -- | Left fold on non-empty vectors foldl1 :: (Vector v a) => (a -> a -> a) -> v a -> a -- | Left fold with strict accumulator foldl' :: (Vector v b) => (a -> b -> a) -> a -> v b -> a -- | Left fold on non-empty vectors with strict accumulator foldl1' :: (Vector v a) => (a -> a -> a) -> v a -> a -- | Right fold foldr :: (Vector v a) => (a -> b -> b) -> b -> v a -> b -- | Right fold on non-empty vectors foldr1 :: (Vector v a) => (a -> a -> a) -> v a -> a -- | Right fold with a strict accumulator foldr' :: (Vector v a) => (a -> b -> b) -> b -> v a -> b -- | Right fold on non-empty vectors with strict accumulator foldr1' :: (Vector v a) => (a -> a -> a) -> v a -> a -- | Left fold (function applied to each element and its index) ifoldl :: (Vector v b) => (a -> Int -> b -> a) -> a -> v b -> a -- | Left fold with strict accumulator (function applied to each element -- and its index) ifoldl' :: (Vector v b) => (a -> Int -> b -> a) -> a -> v b -> a -- | Right fold (function applied to each element and its index) ifoldr :: (Vector v a) => (Int -> a -> b -> b) -> b -> v a -> b -- | Right fold with strict accumulator (function applied to each element -- and its index) ifoldr' :: (Vector v a) => (Int -> a -> b -> b) -> b -> v a -> b all :: (Vector v a) => (a -> Bool) -> v a -> Bool any :: (Vector v a) => (a -> Bool) -> v a -> Bool and :: (Vector v Bool) => v Bool -> Bool or :: (Vector v Bool) => v Bool -> Bool sum :: (Vector v a, Num a) => v a -> a product :: (Vector v a, Num a) => v a -> a maximum :: (Vector v a, Ord a) => v a -> a maximumBy :: (Vector v a) => (a -> a -> Ordering) -> v a -> a minimum :: (Vector v a, Ord a) => v a -> a minimumBy :: (Vector v a) => (a -> a -> Ordering) -> v a -> a minIndex :: (Vector v a, Ord a) => v a -> Int minIndexBy :: (Vector v a) => (a -> a -> Ordering) -> v a -> Int maxIndex :: (Vector v a, Ord a) => v a -> Int maxIndexBy :: (Vector v a) => (a -> a -> Ordering) -> v a -> Int -- | Unfold unfoldr :: (Vector v a) => (b -> Maybe (a, b)) -> b -> v a -- | Unfoldr at most n elements. unfoldrN :: (Vector v a) => Int -> (b -> Maybe (a, b)) -> b -> v a -- | Prefix scan prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Prefix scan with strict accumulator prescanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Suffix scan postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Suffix scan with strict accumulator postscanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Haskell-style scan scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Haskell-style scan with strict accumulator scanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a -- | Scan over a non-empty vector scanl1 :: (Vector v a) => (a -> a -> a) -> v a -> v a -- | Scan over a non-empty vector with a strict accumulator scanl1' :: (Vector v a) => (a -> a -> a) -> v a -> v a -- | Prefix right-to-left scan prescanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Prefix right-to-left scan with strict accumulator prescanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Suffix right-to-left scan postscanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Suffix right-to-left scan with strict accumulator postscanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Haskell-style right-to-left scan scanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Haskell-style right-to-left scan with strict accumulator scanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> v a -> v b -- | Right-to-left scan over a non-empty vector scanr1 :: (Vector v a) => (a -> a -> a) -> v a -> v a -- | Right-to-left scan over a non-empty vector with a strict accumulator scanr1' :: (Vector v a) => (a -> a -> a) -> v a -> v a -- | Yield a vector of the given length containing the values x, -- x+1 etc. This operation is usually more efficient than -- enumFromTo. enumFromN :: (Vector v a, Num a) => a -> Int -> v a -- | Yield a vector of the given length containing the values x, -- x+y, x+y+y etc. This operations is usually more -- efficient than enumFromThenTo. enumFromStepN :: (Vector v a, Num a) => a -> a -> Int -> v a -- | Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (Vector v a, Enum a) => a -> a -> v a -- | Enumerate values from x to y with a specific step -- z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (Vector v a, Enum a) => a -> a -> a -> v a -- | Convert a vector to a list toList :: (Vector v a) => v a -> [a] -- | Convert a list to a vector fromList :: (Vector v a) => [a] -> v a -- | Convert the first n elements of a list to a vector -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: (Vector v a) => Int -> [a] -> v a -- | Perform the monadic action the given number of times and store the -- results in a vector. replicateM :: (Monad m, Vector v a) => Int -> m a -> m (v a) -- | 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) -> v a -> m (v b) -- | Apply the monadic action to all elements of a vector and ignore the -- results mapM_ :: (Monad m, Vector v a) => (a -> m b) -> v a -> m () -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results forM :: (Monad m, Vector v a, Vector v b) => v a -> (a -> m b) -> m (v b) -- | Apply the monadic action to all elements of a vector and ignore the -- results forM_ :: (Monad m, Vector v a) => v a -> (a -> m b) -> m () -- | Zip the two vectors 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) -> v a -> v b -> m (v c) -- | 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) -> v a -> v b -> m () -- | Drop elements that do not satisfy the monadic predicate filterM :: (Monad m, Vector v a) => (a -> m Bool) -> v a -> m (v a) -- | Monadic fold foldM :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> v b -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> v b -> m a -- | Monadic fold over non-empty vectors fold1M :: (Monad m, Vector v a) => (a -> a -> m a) -> v a -> m a -- | Monad fold over non-empty vectors with strict accumulator fold1M' :: (Monad m, Vector v a) => (a -> a -> m a) -> v a -> m a -- | Destructively initialise a vector. create :: (Vector v a) => (forall s. ST s (Mutable v s a)) -> v a -- | Apply a destructive operation to a vector. The operation modifies a -- copy of the vector unless it can be safely performed in place. modify :: (Vector v a) => (forall s. Mutable v s a -> ST s ()) -> v a -> v a -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. copy :: (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> v a -> m () -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. This is not checked. unsafeCopy :: (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> v a -> m () -- | Convert a vector to a Stream stream :: (Vector v a) => v a -> Stream a -- | Create a vector from a Stream unstream :: (Vector v a) => Stream a -> v a -- | Convert a vector to a Stream streamR :: (Vector v a) => v a -> Stream a -- | Create a vector from a Stream unstreamR :: (Vector v a) => Stream a -> v a -- | Construct a pure vector from a monadic initialiser new :: (Vector v a) => New v a -> v a clone :: (Vector v a) => v a -> New v a -- | Generic definion of Data.Data.gfoldl that views a -- Vector as a list. gfoldl :: (Vector v a, Data a) => (forall d b. (Data d) => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> v a -> c (v a) dataCast :: (Vector v a, Data a, Typeable1 v, Typeable1 t) => (forall d. (Data d) => c (t d)) -> Maybe (c (v a)) mkType :: String -> DataType -- | Mutable primitive vectors. module Data.Vector.Primitive.Mutable -- | Mutable vectors of primitive types. data MVector s a MVector :: !!Int -> !!Int -> !!MutableByteArray s -> MVector s a type IOVector = MVector RealWorld type STVector s = MVector s -- | Class of types supporting primitive array operations class Prim a -- | Length of the mutable vector. length :: (Prim a) => MVector s a -> Int overlaps :: (Prim a) => MVector s a -> MVector s a -> Bool -- | Yield a part of the mutable vector without copying it. slice :: (Prim a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. new :: (PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. newWith :: (PrimMonad m, Prim a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. read :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. write :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> m () -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive. grow :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: (Prim a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. The length is not checked. unsafeNewWith :: (PrimMonad m, Prim a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. No bounds checks are -- performed. unsafeSwap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive but this is not checked. unsafeGrow :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) instance Typeable2 MVector instance (Prim a) => MVector MVector a -- | Unboxed vectors of primitive types. module Data.Vector.Primitive -- | Unboxed vectors of primitive types data Vector a -- | Mutable vectors of primitive types. data MVector s a MVector :: !!Int -> !!Int -> !!MutableByteArray s -> MVector s a -- | Class of types supporting primitive array operations class Prim a length :: (Prim a) => Vector a -> Int null :: (Prim a) => Vector a -> Bool -- | Empty vector empty :: (Prim a) => Vector a -- | Vector with exaclty one element singleton :: (Prim a) => a -> Vector a -- | Prepend an element cons :: (Prim a) => a -> Vector a -> Vector a -- | Append an element snoc :: (Prim a) => Vector a -> a -> Vector a -- | Vector of the given length with the given value in each position replicate :: (Prim a) => Int -> a -> Vector a -- | Generate a vector of the given length by applying the function to each -- index generate :: (Prim a) => Int -> (Int -> a) -> Vector a -- | Concatenate two vectors (++) :: (Prim a) => Vector a -> Vector a -> Vector a -- | Create a copy of a vector. Useful when dealing with slices. force :: (Prim a) => Vector a -> Vector a -- | Indexing (!) :: (Prim a) => Vector a -> Int -> a -- | First element head :: (Prim a) => Vector a -> a -- | Last element last :: (Prim a) => Vector a -> a -- | Monadic indexing which can be strict in the vector while remaining -- lazy in the element indexM :: (Prim a, Monad m) => Vector a -> Int -> m a headM :: (Prim a, Monad m) => Vector a -> m a lastM :: (Prim a, Monad m) => Vector a -> m a -- | Unsafe indexing without bounds checking unsafeIndex :: (Prim a) => Vector a -> Int -> a -- | Yield the first element of a vector without checking if the vector is -- empty unsafeHead :: (Prim a) => Vector a -> a -- | Yield the last element of a vector without checking if the vector is -- empty unsafeLast :: (Prim a) => Vector a -> a -- | Unsafe monadic indexing without bounds checks unsafeIndexM :: (Prim a, Monad m) => Vector a -> Int -> m a unsafeHeadM :: (Prim a, Monad m) => Vector a -> m a unsafeLastM :: (Prim a, Monad m) => Vector a -> m a -- | Yield a part of the vector without copying it. Safer version of -- basicUnsafeSlice. slice :: (Prim a) => Int -> Int -> Vector a -> Vector a -- | Yield all but the last element without copying. init :: (Prim a) => Vector a -> Vector a -- | All but the first element (without copying). tail :: (Prim a) => Vector a -> Vector a -- | Yield the first n elements without copying. take :: (Prim a) => Int -> Vector a -> Vector a -- | Yield all but the first n elements without copying. drop :: (Prim a) => Int -> Vector a -> Vector a -- | Unsafely yield a part of the vector without copying it and without -- performing bounds checks. unsafeSlice :: (Prim a) => Int -> Int -> Vector a -> Vector a unsafeInit :: (Prim a) => Vector a -> Vector a unsafeTail :: (Prim a) => Vector a -> Vector a unsafeTake :: (Prim a) => Int -> Vector a -> Vector a unsafeDrop :: (Prim a) => Int -> Vector a -> Vector a accum :: (Prim a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a accumulate_ :: (Prim a, Prim b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a (//) :: (Prim a) => Vector a -> [(Int, a)] -> Vector a update_ :: (Prim a) => Vector a -> Vector Int -> Vector a -> Vector a backpermute :: (Prim a) => Vector a -> Vector Int -> Vector a reverse :: (Prim a) => Vector a -> Vector a unsafeAccum :: (Prim a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a unsafeAccumulate_ :: (Prim a, Prim b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a unsafeUpd :: (Prim a) => Vector a -> [(Int, a)] -> Vector a unsafeUpdate_ :: (Prim a) => Vector a -> Vector Int -> Vector a -> Vector a unsafeBackpermute :: (Prim a) => Vector a -> Vector Int -> Vector a -- | Map a function over a vector map :: (Prim a, Prim b) => (a -> b) -> Vector a -> Vector b -- | Apply a function to every index/value pair imap :: (Prim a, Prim b) => (Int -> a -> b) -> Vector a -> Vector b concatMap :: (Prim a, Prim b) => (a -> Vector b) -> Vector a -> Vector b -- | Zip two vectors with the given function. zipWith :: (Prim a, Prim b, Prim c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors with the given function. zipWith3 :: (Prim a, Prim b, Prim c, Prim d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d zipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e) => (a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e zipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f) => (a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f zipWith6 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g) => (a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g -- | Zip two vectors and their indices with the given function. izipWith :: (Prim a, Prim b, Prim c) => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors and their indices with the given function. izipWith3 :: (Prim a, Prim b, Prim c, Prim d) => (Int -> a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d izipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e) => (Int -> a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e izipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f izipWith6 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g) => (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g -- | Drop elements which do not satisfy the predicate filter :: (Prim a) => (a -> Bool) -> Vector a -> Vector a -- | Drop elements that do not satisfy the predicate (applied to values and -- their indices) ifilter :: (Prim a) => (Int -> a -> Bool) -> Vector a -> Vector a -- | Yield the longest prefix of elements satisfying the predicate. takeWhile :: (Prim a) => (a -> Bool) -> Vector a -> Vector a -- | Drop the longest prefix of elements that satisfy the predicate. dropWhile :: (Prim a) => (a -> Bool) -> Vector a -> Vector a -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- relative order of the elements is preserved at the cost of a -- (sometimes) reduced performance compared to unstablePartition. partition :: (Prim a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- order of the elements is not preserved. unstablePartition :: (Prim a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that satisfy the -- predicate and the rest. span :: (Prim a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that do not -- satisfy the predicate and the rest. break :: (Prim a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Check whether the vector contains an element elem :: (Prim a, Eq a) => a -> Vector a -> Bool -- | Inverse of elem notElem :: (Prim a, Eq a) => a -> Vector a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (Prim a) => (a -> Bool) -> Vector a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (Prim a) => (a -> Bool) -> Vector a -> Maybe Int -- | Yield the indices of elements satisfying the predicate findIndices :: (Prim a) => (a -> Bool) -> Vector a -> Vector Int -- | Yield Just the index of the first occurence of the given -- element or Nothing if the vector does not contain the element elemIndex :: (Prim a, Eq a) => a -> Vector a -> Maybe Int -- | Yield the indices of all occurences of the given element elemIndices :: (Prim a, Eq a) => a -> Vector a -> Vector Int -- | Left fold foldl :: (Prim b) => (a -> b -> a) -> a -> Vector b -> a -- | Lefgt fold on non-empty vectors foldl1 :: (Prim a) => (a -> a -> a) -> Vector a -> a -- | Left fold with strict accumulator foldl' :: (Prim b) => (a -> b -> a) -> a -> Vector b -> a -- | Left fold on non-empty vectors with strict accumulator foldl1' :: (Prim a) => (a -> a -> a) -> Vector a -> a -- | Right fold foldr :: (Prim a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors foldr1 :: (Prim a) => (a -> a -> a) -> Vector a -> a -- | Right fold with a strict accumulator foldr' :: (Prim a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors with strict accumulator foldr1' :: (Prim a) => (a -> a -> a) -> Vector a -> a -- | Left fold (function applied to each element and its index) ifoldl :: (Prim b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Left fold with strict accumulator (function applied to each element -- and its index) ifoldl' :: (Prim b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Right fold (function applied to each element and its index) ifoldr :: (Prim a) => (Int -> a -> b -> b) -> b -> Vector a -> b -- | Right fold with strict accumulator (function applied to each element -- and its index) ifoldr' :: (Prim a) => (Int -> a -> b -> b) -> b -> Vector a -> b all :: (Prim a) => (a -> Bool) -> Vector a -> Bool any :: (Prim a) => (a -> Bool) -> Vector a -> Bool sum :: (Prim a, Num a) => Vector a -> a product :: (Prim a, Num a) => Vector a -> a maximum :: (Prim a, Ord a) => Vector a -> a maximumBy :: (Prim a) => (a -> a -> Ordering) -> Vector a -> a minimum :: (Prim a, Ord a) => Vector a -> a minimumBy :: (Prim a) => (a -> a -> Ordering) -> Vector a -> a minIndex :: (Prim a, Ord a) => Vector a -> Int minIndexBy :: (Prim a) => (a -> a -> Ordering) -> Vector a -> Int maxIndex :: (Prim a, Ord a) => Vector a -> Int maxIndexBy :: (Prim a) => (a -> a -> Ordering) -> Vector a -> Int -- | The unfoldr function is a `dual' to foldr: while -- foldr reduces a vector to a summary value, unfoldr -- builds a list from a seed value. The function takes the element and -- returns Nothing if it is done generating the vector or returns -- Just (a,b), in which case, a is a prepended -- to the vector and b is used as the next element in a -- recursive call. -- -- A simple use of unfoldr: -- --
-- unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfoldr :: (Prim a) => (b -> Maybe (a, b)) -> b -> Vector a -- | Unfold at most n elements unfoldrN :: (Prim a) => Int -> (b -> Maybe (a, b)) -> b -> Vector a -- | Prefix scan prescanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Prefix scan with strict accumulator prescanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan postscanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan with strict accumulator postscanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan scanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan with strict accumulator scanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Scan over a non-empty Vector scanl1 :: (Prim a) => (a -> a -> a) -> Vector a -> Vector a -- | Scan over a non-empty Vector with a strict accumulator scanl1' :: (Prim a) => (a -> a -> a) -> Vector a -> Vector a -- | Prefix right-to-left scan prescanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Prefix right-to-left scan with strict accumulator prescanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan postscanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan with strict accumulator postscanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan scanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan with strict accumulator scanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Right-to-left scan over a non-empty vector scanr1 :: (Prim a) => (a -> a -> a) -> Vector a -> Vector a -- | Right-to-left scan over a non-empty vector with a strict accumulator scanr1' :: (Prim a) => (a -> a -> a) -> Vector a -> Vector a -- | Yield a vector of the given length containing the values x, -- x+1 etc. This operation is usually more efficient than -- enumFromTo. enumFromN :: (Prim a, Num a) => a -> Int -> Vector a -- | Yield a vector of the given length containing the values x, -- x+y, x+y+y etc. This operations is usually more -- efficient than enumFromThenTo. enumFromStepN :: (Prim a, Num a) => a -> a -> Int -> Vector a -- | Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (Prim a, Enum a) => a -> a -> Vector a -- | Enumerate values from x to y with a specific step -- z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (Prim a, Enum a) => a -> a -> a -> Vector a -- | Convert a vector to a list toList :: (Prim a) => Vector a -> [a] -- | Convert a list to a vector fromList :: (Prim a) => [a] -> Vector a -- | Convert the first n elements of a list to a vector -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: (Prim a) => Int -> [a] -> Vector a -- | Perform the monadic action the given number of times and store the -- results in a vector. replicateM :: (Monad m, Prim a) => Int -> m a -> m (Vector a) -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results mapM :: (Monad m, Prim a, Prim b) => (a -> m b) -> Vector a -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results mapM_ :: (Monad m, Prim a) => (a -> m b) -> Vector a -> m () -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results forM :: (Monad m, Prim a, Prim b) => Vector a -> (a -> m b) -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results forM_ :: (Monad m, Prim a) => Vector a -> (a -> m b) -> m () -- | Zip the two vectors with the monadic action and yield a vector of -- results zipWithM :: (Monad m, Prim a, Prim b, Prim c) => (a -> b -> m c) -> Vector a -> Vector b -> m (Vector c) -- | Zip the two vectors with the monadic action and ignore the results zipWithM_ :: (Monad m, Prim a, Prim b) => (a -> b -> m c) -> Vector a -> Vector b -> m () -- | Drop elements that do not satisfy the monadic predicate filterM :: (Monad m, Prim a) => (a -> m Bool) -> Vector a -> m (Vector a) -- | Monadic fold foldM :: (Monad m, Prim b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m, Prim b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold over non-empty vectors fold1M :: (Monad m, Prim a) => (a -> a -> m a) -> Vector a -> m a -- | Monad fold over non-empty vectors with strict accumulator fold1M' :: (Monad m, Prim a) => (a -> a -> m a) -> Vector a -> m a -- | Destructively initialise a vector. create :: (Prim a) => (forall s. ST s (MVector s a)) -> Vector a -- | Apply a destructive operation to a vector. The operation is applied to -- a copy of the vector unless it can be safely performed in place. modify :: (Prim a) => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. copy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. This is not checked. unsafeCopy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () instance Typeable1 Vector instance (Prim a, Ord a) => Ord (Vector a) instance (Prim a, Eq a) => Eq (Vector a) instance (Prim a) => Vector Vector a instance (Data a, Prim a) => Data (Vector a) instance (Show a, Prim a) => Show (Vector a) -- | Mutable vectors based on Storable. module Data.Vector.Storable.Mutable -- | Mutable Storable-based vectors data MVector s a MVector :: !!Ptr a -> !!Int -> !!ForeignPtr a -> MVector s a type IOVector = MVector RealWorld type STVector s = MVector s -- | The member functions of this class facilitate writing values of -- primitive types to raw memory (which may have been allocated with the -- above mentioned routines) and reading values from blocks of raw -- memory. The class, furthermore, includes support for computing the -- storage requirements and alignment restrictions of storable types. -- -- Memory addresses are represented as values of type Ptr -- a, for some a which is an instance of class -- Storable. The type argument to Ptr helps provide some -- valuable type safety in FFI code (you can't mix pointers of different -- types without an explicit cast), while helping the Haskell type system -- figure out which marshalling method is needed for a given pointer. -- -- All marshalling between Haskell and a foreign language ultimately -- boils down to translating Haskell data structures into the binary -- representation of a corresponding data structure of the foreign -- language and vice versa. To code this marshalling in Haskell, it is -- necessary to manipulate primitive data types stored in unstructured -- memory blocks. The class Storable facilitates this manipulation -- on all types for which it is instantiated, which are the standard -- basic types of Haskell, the fixed size Int types -- (Int8, Int16, Int32, Int64), the fixed -- size Word types (Word8, Word16, Word32, -- Word64), StablePtr, all types from -- Foreign.C.Types, as well as Ptr. -- -- Minimal complete definition: sizeOf, alignment, one of -- peek, peekElemOff and peekByteOff, and one of -- poke, pokeElemOff and pokeByteOff. class Storable a -- | Length of the mutable vector. length :: (Storable a) => MVector s a -> Int overlaps :: (Storable a) => MVector s a -> MVector s a -> Bool -- | Yield a part of the mutable vector without copying it. slice :: (Storable a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. new :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. newWith :: (PrimMonad m, Storable a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. read :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. write :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> m () -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive. grow :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: (Storable a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. The length is not checked. unsafeNewWith :: (PrimMonad m, Storable a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. No bounds checks are -- performed. unsafeSwap :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive but this is not checked. unsafeGrow :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) -- | Create a mutable vector from a ForeignPtr with an offset and a -- length. Modifying data through the ForeignPtr afterwards is -- unsafe if the vector could have been frozen before the modification. unsafeFromForeignPtr :: (Storable a) => ForeignPtr a -> Int -> Int -> MVector s a -- | Yield the underlying ForeignPtr together with the offset to the -- data and its length. Modifying the data through the ForeignPtr -- is unsafe if the vector could have frozen before the modification. unsafeToForeignPtr :: (Storable a) => MVector s a -> (ForeignPtr a, Int, Int) -- | Pass a pointer to the vector's data to the IO action. Modifying data -- through the pointer is unsafe if the vector could have been frozen -- before the modification. unsafeWith :: (Storable a) => IOVector a -> (Ptr a -> IO b) -> IO b instance Typeable2 MVector instance (Storable a) => MVector MVector a -- | Storable-based vectors. module Data.Vector.Storable -- | Storable-based vectors data Vector a -- | Mutable Storable-based vectors data MVector s a MVector :: !!Ptr a -> !!Int -> !!ForeignPtr a -> MVector s a -- | The member functions of this class facilitate writing values of -- primitive types to raw memory (which may have been allocated with the -- above mentioned routines) and reading values from blocks of raw -- memory. The class, furthermore, includes support for computing the -- storage requirements and alignment restrictions of storable types. -- -- Memory addresses are represented as values of type Ptr -- a, for some a which is an instance of class -- Storable. The type argument to Ptr helps provide some -- valuable type safety in FFI code (you can't mix pointers of different -- types without an explicit cast), while helping the Haskell type system -- figure out which marshalling method is needed for a given pointer. -- -- All marshalling between Haskell and a foreign language ultimately -- boils down to translating Haskell data structures into the binary -- representation of a corresponding data structure of the foreign -- language and vice versa. To code this marshalling in Haskell, it is -- necessary to manipulate primitive data types stored in unstructured -- memory blocks. The class Storable facilitates this manipulation -- on all types for which it is instantiated, which are the standard -- basic types of Haskell, the fixed size Int types -- (Int8, Int16, Int32, Int64), the fixed -- size Word types (Word8, Word16, Word32, -- Word64), StablePtr, all types from -- Foreign.C.Types, as well as Ptr. -- -- Minimal complete definition: sizeOf, alignment, one of -- peek, peekElemOff and peekByteOff, and one of -- poke, pokeElemOff and pokeByteOff. class Storable a length :: (Storable a) => Vector a -> Int null :: (Storable a) => Vector a -> Bool -- | Empty vector empty :: (Storable a) => Vector a -- | Vector with exaclty one element singleton :: (Storable a) => a -> Vector a -- | Prepend an element cons :: (Storable a) => a -> Vector a -> Vector a -- | Append an element snoc :: (Storable a) => Vector a -> a -> Vector a -- | Vector of the given length with the given value in each position replicate :: (Storable a) => Int -> a -> Vector a -- | Generate a vector of the given length by applying the function to each -- index generate :: (Storable a) => Int -> (Int -> a) -> Vector a -- | Concatenate two vectors (++) :: (Storable a) => Vector a -> Vector a -> Vector a -- | Create a copy of a vector. Useful when dealing with slices. force :: (Storable a) => Vector a -> Vector a -- | Indexing (!) :: (Storable a) => Vector a -> Int -> a -- | First element head :: (Storable a) => Vector a -> a -- | Last element last :: (Storable a) => Vector a -> a -- | Monadic indexing which can be strict in the vector while remaining -- lazy in the element indexM :: (Storable a, Monad m) => Vector a -> Int -> m a headM :: (Storable a, Monad m) => Vector a -> m a lastM :: (Storable a, Monad m) => Vector a -> m a -- | Unsafe indexing without bounds checking unsafeIndex :: (Storable a) => Vector a -> Int -> a -- | Yield the first element of a vector without checking if the vector is -- empty unsafeHead :: (Storable a) => Vector a -> a -- | Yield the last element of a vector without checking if the vector is -- empty unsafeLast :: (Storable a) => Vector a -> a -- | Unsafe monadic indexing without bounds checks unsafeIndexM :: (Storable a, Monad m) => Vector a -> Int -> m a unsafeHeadM :: (Storable a, Monad m) => Vector a -> m a unsafeLastM :: (Storable a, Monad m) => Vector a -> m a -- | Yield a part of the vector without copying it. Safer version of -- basicUnsafeSlice. slice :: (Storable a) => Int -> Int -> Vector a -> Vector a -- | Yield all but the last element without copying. init :: (Storable a) => Vector a -> Vector a -- | All but the first element (without copying). tail :: (Storable a) => Vector a -> Vector a -- | Yield the first n elements without copying. take :: (Storable a) => Int -> Vector a -> Vector a -- | Yield all but the first n elements without copying. drop :: (Storable a) => Int -> Vector a -> Vector a -- | Unsafely yield a part of the vector without copying it and without -- performing bounds checks. unsafeSlice :: (Storable a) => Int -> Int -> Vector a -> Vector a unsafeInit :: (Storable a) => Vector a -> Vector a unsafeTail :: (Storable a) => Vector a -> Vector a unsafeTake :: (Storable a) => Int -> Vector a -> Vector a unsafeDrop :: (Storable a) => Int -> Vector a -> Vector a accum :: (Storable a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a accumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a (//) :: (Storable a) => Vector a -> [(Int, a)] -> Vector a update_ :: (Storable a) => Vector a -> Vector Int -> Vector a -> Vector a backpermute :: (Storable a) => Vector a -> Vector Int -> Vector a reverse :: (Storable a) => Vector a -> Vector a unsafeAccum :: (Storable a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a unsafeAccumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a unsafeUpd :: (Storable a) => Vector a -> [(Int, a)] -> Vector a unsafeUpdate_ :: (Storable a) => Vector a -> Vector Int -> Vector a -> Vector a unsafeBackpermute :: (Storable a) => Vector a -> Vector Int -> Vector a -- | Map a function over a vector map :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b -- | Apply a function to every index/value pair imap :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b concatMap :: (Storable a, Storable b) => (a -> Vector b) -> Vector a -> Vector b -- | Zip two vectors with the given function. zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors with the given function. zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e zipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f zipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => (a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g -- | Zip two vectors and their indices with the given function. izipWith :: (Storable a, Storable b, Storable c) => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors and their indices with the given function. izipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (Int -> a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d izipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (Int -> a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e izipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector 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 a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g -- | Drop elements which do not satisfy the predicate filter :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | Drop elements that do not satisfy the predicate (applied to values and -- their indices) ifilter :: (Storable a) => (Int -> a -> Bool) -> Vector a -> Vector a -- | Yield the longest prefix of elements satisfying the predicate. takeWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | Drop the longest prefix of elements that satisfy the predicate. dropWhile :: (Storable a) => (a -> Bool) -> Vector a -> Vector a -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- relative order of the elements is preserved at the cost of a -- (sometimes) reduced performance compared to unstablePartition. partition :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- order of the elements is not preserved. unstablePartition :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that satisfy the -- predicate and the rest. span :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that do not -- satisfy the predicate and the rest. break :: (Storable a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Check whether the vector contains an element elem :: (Storable a, Eq a) => a -> Vector a -> Bool -- | Inverse of elem notElem :: (Storable a, Eq a) => a -> Vector a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (Storable a) => (a -> Bool) -> Vector a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (Storable a) => (a -> Bool) -> Vector a -> Maybe Int -- | Yield the indices of elements satisfying the predicate findIndices :: (Storable a) => (a -> Bool) -> Vector a -> Vector Int -- | Yield Just the index of the first occurence of the given -- element or Nothing if the vector does not contain the element elemIndex :: (Storable a, Eq a) => a -> Vector a -> Maybe Int -- | Yield the indices of all occurences of the given element elemIndices :: (Storable a, Eq a) => a -> Vector a -> Vector Int -- | Left fold foldl :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a -- | Lefgt fold on non-empty vectors foldl1 :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | Left fold with strict accumulator foldl' :: (Storable b) => (a -> b -> a) -> a -> Vector b -> a -- | Left fold on non-empty vectors with strict accumulator foldl1' :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | Right fold foldr :: (Storable a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors foldr1 :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | Right fold with a strict accumulator foldr' :: (Storable a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors with strict accumulator foldr1' :: (Storable a) => (a -> a -> a) -> Vector a -> a -- | Left fold (function applied to each element and its index) ifoldl :: (Storable b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Left fold with strict accumulator (function applied to each element -- and its index) ifoldl' :: (Storable b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Right fold (function applied to each element and its index) ifoldr :: (Storable a) => (Int -> a -> b -> b) -> b -> Vector a -> b -- | Right fold with strict accumulator (function applied to each element -- and its index) ifoldr' :: (Storable a) => (Int -> a -> b -> b) -> b -> Vector a -> b all :: (Storable a) => (a -> Bool) -> Vector a -> Bool any :: (Storable a) => (a -> Bool) -> Vector a -> Bool and :: Vector Bool -> Bool or :: Vector Bool -> Bool sum :: (Storable a, Num a) => Vector a -> a product :: (Storable a, Num a) => Vector a -> a maximum :: (Storable a, Ord a) => Vector a -> a maximumBy :: (Storable a) => (a -> a -> Ordering) -> Vector a -> a minimum :: (Storable a, Ord a) => Vector a -> a minimumBy :: (Storable a) => (a -> a -> Ordering) -> Vector a -> a minIndex :: (Storable a, Ord a) => Vector a -> Int minIndexBy :: (Storable a) => (a -> a -> Ordering) -> Vector a -> Int maxIndex :: (Storable a, Ord a) => Vector a -> Int maxIndexBy :: (Storable a) => (a -> a -> Ordering) -> Vector a -> Int -- | The unfoldr function is a `dual' to foldr: while -- foldr reduces a vector to a summary value, unfoldr -- builds a list from a seed value. The function takes the element and -- returns Nothing if it is done generating the vector or returns -- Just (a,b), in which case, a is a prepended -- to the vector and b is used as the next element in a -- recursive call. -- -- A simple use of unfoldr: -- --
-- unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfoldr :: (Storable a) => (b -> Maybe (a, b)) -> b -> Vector a -- | Unfold at most n elements unfoldrN :: (Storable a) => Int -> (b -> Maybe (a, b)) -> b -> Vector a -- | Prefix scan prescanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Prefix scan with strict accumulator prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan with strict accumulator postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan with strict accumulator scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Scan over a non-empty Vector scanl1 :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | Scan over a non-empty Vector with a strict accumulator scanl1' :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | Prefix right-to-left scan prescanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Prefix right-to-left scan with strict accumulator prescanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan postscanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan with strict accumulator postscanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan scanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan with strict accumulator scanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Right-to-left scan over a non-empty vector scanr1 :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | Right-to-left scan over a non-empty vector with a strict accumulator scanr1' :: (Storable a) => (a -> a -> a) -> Vector a -> Vector a -- | Yield a vector of the given length containing the values x, -- x+1 etc. This operation is usually more efficient than -- enumFromTo. enumFromN :: (Storable a, Num a) => a -> Int -> Vector a -- | Yield a vector of the given length containing the values x, -- x+y, x+y+y etc. This operations is usually more -- efficient than enumFromThenTo. enumFromStepN :: (Storable a, Num a) => a -> a -> Int -> Vector a -- | Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (Storable a, Enum a) => a -> a -> Vector a -- | Enumerate values from x to y with a specific step -- z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (Storable a, Enum a) => a -> a -> a -> Vector a -- | Convert a vector to a list toList :: (Storable a) => Vector a -> [a] -- | Convert a list to a vector fromList :: (Storable a) => [a] -> Vector a -- | Convert the first n elements of a list to a vector -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: (Storable a) => Int -> [a] -> Vector a -- | Perform the monadic action the given number of times and store the -- results in a vector. replicateM :: (Monad m, Storable a) => Int -> m a -> m (Vector a) -- | 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 a -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results mapM_ :: (Monad m, Storable a) => (a -> m b) -> Vector a -> m () -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results forM :: (Monad m, Storable a, Storable b) => Vector a -> (a -> m b) -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results forM_ :: (Monad m, Storable a) => Vector a -> (a -> m b) -> m () -- | Zip the two vectors with the monadic action and yield a vector of -- results zipWithM :: (Monad m, Storable a, Storable b, Storable c) => (a -> b -> m c) -> Vector a -> Vector b -> m (Vector c) -- | Zip the two vectors with the monadic action and ignore the results zipWithM_ :: (Monad m, Storable a, Storable b) => (a -> b -> m c) -> Vector a -> Vector b -> m () -- | Drop elements that do not satisfy the monadic predicate filterM :: (Monad m, Storable a) => (a -> m Bool) -> Vector a -> m (Vector a) -- | Monadic fold foldM :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold over non-empty vectors fold1M :: (Monad m, Storable a) => (a -> a -> m a) -> Vector a -> m a -- | Monad fold over non-empty vectors with strict accumulator fold1M' :: (Monad m, Storable a) => (a -> a -> m a) -> Vector a -> m a -- | Destructively initialise a vector. create :: (Storable a) => (forall s. ST s (MVector s a)) -> Vector a -- | Apply a destructive operation to a vector. The operation is applied to -- a copy of the vector unless it can be safely performed in place. modify :: (Storable a) => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. copy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. This is not checked. unsafeCopy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () -- | Create a vector from a ForeignPtr with an offset and a length. -- The data may not be modified through the ForeignPtr afterwards. unsafeFromForeignPtr :: (Storable a) => ForeignPtr a -> Int -> Int -> Vector a -- | Yield the underlying ForeignPtr together with the offset to the -- data and its length. The data may not be modified through the -- ForeignPtr. unsafeToForeignPtr :: (Storable a) => Vector a -> (ForeignPtr a, Int, Int) -- | Pass a pointer to the vector's data to the IO action. The data may not -- be modified through the 'Ptr. unsafeWith :: (Storable a) => Vector a -> (Ptr a -> IO b) -> IO b instance Typeable1 Vector instance (Storable a, Ord a) => Ord (Vector a) instance (Storable a, Eq a) => Eq (Vector a) instance (Storable a) => Vector Vector a instance (Data a, Storable a) => Data (Vector a) instance (Show a, Storable a) => Show (Vector a) -- | Adaptive unboxed vectors: basic implementation module Data.Vector.Unboxed.Base type IOVector = MVector RealWorld type STVector s = MVector s class (Vector Vector a, MVector MVector a) => Unbox a instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Vector Vector (a, b, c, d, e, f) instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => MVector MVector (a, b, c, d, e, f) instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Unbox (a, b, c, d, e, f) instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector Vector (a, b, c, d, e) instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => MVector MVector (a, b, c, d, e) instance (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Unbox (a, b, c, d, e) instance (Unbox a, Unbox b, Unbox c, Unbox d) => Vector Vector (a, b, c, d) instance (Unbox a, Unbox b, Unbox c, Unbox d) => MVector MVector (a, b, c, d) instance (Unbox a, Unbox b, Unbox c, Unbox d) => Unbox (a, b, c, d) instance (Unbox a, Unbox b, Unbox c) => Vector Vector (a, b, c) instance (Unbox a, Unbox b, Unbox c) => MVector MVector (a, b, c) instance (Unbox a, Unbox b, Unbox c) => Unbox (a, b, c) instance (Unbox a, Unbox b) => Vector Vector (a, b) instance (Unbox a, Unbox b) => MVector MVector (a, b) instance (Unbox a, Unbox b) => Unbox (a, b) instance (RealFloat a, Unbox a) => Vector Vector (Complex a) instance (RealFloat a, Unbox a) => MVector MVector (Complex a) instance (RealFloat a, Unbox a) => Unbox (Complex a) instance Vector Vector Bool instance MVector MVector Bool instance Unbox Bool instance Vector Vector Char instance MVector MVector Char instance Unbox Char instance Vector Vector Double instance MVector MVector Double instance Unbox Double instance Vector Vector Float instance MVector MVector Float instance Unbox Float instance Vector Vector Word64 instance MVector MVector Word64 instance Unbox Word64 instance Vector Vector Word32 instance MVector MVector Word32 instance Unbox Word32 instance Vector Vector Word16 instance MVector MVector Word16 instance Unbox Word16 instance Vector Vector Word8 instance MVector MVector Word8 instance Unbox Word8 instance Vector Vector Word instance MVector MVector Word instance Unbox Word instance Vector Vector Int64 instance MVector MVector Int64 instance Unbox Int64 instance Vector Vector Int32 instance MVector MVector Int32 instance Unbox Int32 instance Vector Vector Int16 instance MVector MVector Int16 instance Unbox Int16 instance Vector Vector Int8 instance MVector MVector Int8 instance Unbox Int8 instance Vector Vector Int instance MVector MVector Int instance Unbox Int instance Vector Vector () instance MVector MVector () instance Unbox () instance (Data a, Unbox a) => Data (Vector a) instance Typeable2 MVector instance Typeable1 Vector -- | Adaptive unboxed vectors module Data.Vector.Unboxed class (Vector Vector a, MVector MVector a) => Unbox a length :: (Unbox a) => Vector a -> Int null :: (Unbox a) => Vector a -> Bool -- | Empty vector empty :: (Unbox a) => Vector a -- | Vector with exaclty one element singleton :: (Unbox a) => a -> Vector a -- | Prepend an element cons :: (Unbox a) => a -> Vector a -> Vector a -- | Append an element snoc :: (Unbox a) => Vector a -> a -> Vector a -- | Vector of the given length with the given value in each position replicate :: (Unbox a) => Int -> a -> Vector a -- | Generate a vector of the given length by applying the function to each -- index generate :: (Unbox a) => Int -> (Int -> a) -> Vector a -- | Concatenate two vectors (++) :: (Unbox a) => Vector a -> Vector a -> Vector a -- | Create a copy of a vector. Useful when dealing with slices. force :: (Unbox a) => Vector a -> Vector a -- | Indexing (!) :: (Unbox a) => Vector a -> Int -> a -- | First element head :: (Unbox a) => Vector a -> a -- | Last element last :: (Unbox a) => Vector a -> a -- | Monadic indexing which can be strict in the vector while remaining -- lazy in the element indexM :: (Unbox a, Monad m) => Vector a -> Int -> m a headM :: (Unbox a, Monad m) => Vector a -> m a lastM :: (Unbox a, Monad m) => Vector a -> m a -- | Unsafe indexing without bounds checking unsafeIndex :: (Unbox a) => Vector a -> Int -> a -- | Yield the first element of a vector without checking if the vector is -- empty unsafeHead :: (Unbox a) => Vector a -> a -- | Yield the last element of a vector without checking if the vector is -- empty unsafeLast :: (Unbox a) => Vector a -> a -- | Unsafe monadic indexing without bounds checks unsafeIndexM :: (Unbox a, Monad m) => Vector a -> Int -> m a unsafeHeadM :: (Unbox a, Monad m) => Vector a -> m a unsafeLastM :: (Unbox a, Monad m) => Vector a -> m a -- | Yield a part of the vector without copying it. Safer version of -- basicUnsafeSlice. slice :: (Unbox a) => Int -> Int -> Vector a -> Vector a -- | Yield all but the last element without copying. init :: (Unbox a) => Vector a -> Vector a -- | All but the first element (without copying). tail :: (Unbox a) => Vector a -> Vector a -- | Yield the first n elements without copying. take :: (Unbox a) => Int -> Vector a -> Vector a -- | Yield all but the first n elements without copying. drop :: (Unbox a) => Int -> Vector a -> Vector a -- | Unsafely yield a part of the vector without copying it and without -- performing bounds checks. unsafeSlice :: (Unbox a) => Int -> Int -> Vector a -> Vector a unsafeInit :: (Unbox a) => Vector a -> Vector a unsafeTail :: (Unbox a) => Vector a -> Vector a unsafeTake :: (Unbox a) => Int -> Vector a -> Vector a unsafeDrop :: (Unbox a) => Int -> Vector a -> Vector a accum :: (Unbox a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a accumulate :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector a -> Vector (Int, b) -> Vector a accumulate_ :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a (//) :: (Unbox a) => Vector a -> [(Int, a)] -> Vector a update :: (Unbox a) => Vector a -> Vector (Int, a) -> Vector a update_ :: (Unbox a) => Vector a -> Vector Int -> Vector a -> Vector a backpermute :: (Unbox a) => Vector a -> Vector Int -> Vector a reverse :: (Unbox a) => Vector a -> Vector a unsafeAccum :: (Unbox a) => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a unsafeAccumulate :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector a -> Vector (Int, b) -> Vector a unsafeAccumulate_ :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a unsafeUpd :: (Unbox a) => Vector a -> [(Int, a)] -> Vector a unsafeUpdate :: (Unbox a) => Vector a -> Vector (Int, a) -> Vector a unsafeUpdate_ :: (Unbox a) => Vector a -> Vector Int -> Vector a -> Vector a unsafeBackpermute :: (Unbox a) => Vector a -> Vector Int -> Vector a -- | Map a function over a vector map :: (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b -- | Apply a function to every index/value pair imap :: (Unbox a, Unbox b) => (Int -> a -> b) -> Vector a -> Vector b concatMap :: (Unbox a, Unbox b) => (a -> Vector b) -> Vector a -> Vector b -- | Zip two vectors with the given function. zipWith :: (Unbox a, Unbox b, Unbox c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors with the given function. zipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d zipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => (a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e zipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => (a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f zipWith6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox g) => (a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g -- | Zip two vectors and their indices with the given function. izipWith :: (Unbox a, Unbox b, Unbox c) => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Zip three vectors and their indices with the given function. izipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d) => (Int -> a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d izipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => (Int -> a -> b -> c -> d -> e) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e izipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f izipWith6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox g) => (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector g zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b) zip3 :: (Unbox a, Unbox b, Unbox c) => Vector a -> Vector b -> Vector c -> Vector (a, b, c) zip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => Vector a -> Vector b -> Vector c -> Vector d -> Vector (a, b, c, d) zip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector (a, b, c, d, e) zip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f -> Vector (a, b, c, d, e, f) unzip :: (Unbox a, Unbox b) => Vector (a, b) -> (Vector a, Vector b) unzip3 :: (Unbox a, Unbox b, Unbox c) => Vector (a, b, c) -> (Vector a, Vector b, Vector c) unzip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => Vector (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d) unzip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector (a, b, c, d, e) -> (Vector a, Vector b, Vector c, Vector d, Vector e) unzip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Vector (a, b, c, d, e, f) -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f) -- | Drop elements which do not satisfy the predicate filter :: (Unbox a) => (a -> Bool) -> Vector a -> Vector a -- | Drop elements that do not satisfy the predicate (applied to values and -- their indices) ifilter :: (Unbox a) => (Int -> a -> Bool) -> Vector a -> Vector a -- | Yield the longest prefix of elements satisfying the predicate. takeWhile :: (Unbox a) => (a -> Bool) -> Vector a -> Vector a -- | Drop the longest prefix of elements that satisfy the predicate. dropWhile :: (Unbox a) => (a -> Bool) -> Vector a -> Vector a -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- relative order of the elements is preserved at the cost of a -- (sometimes) reduced performance compared to unstablePartition. partition :: (Unbox a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector in two parts, the first one containing those elements -- that satisfy the predicate and the second one those that don't. The -- order of the elements is not preserved. unstablePartition :: (Unbox a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that satisfy the -- predicate and the rest. span :: (Unbox a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Split the vector into the longest prefix of elements that do not -- satisfy the predicate and the rest. break :: (Unbox a) => (a -> Bool) -> Vector a -> (Vector a, Vector a) -- | Check whether the vector contains an element elem :: (Unbox a, Eq a) => a -> Vector a -> Bool -- | Inverse of elem notElem :: (Unbox a, Eq a) => a -> Vector a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (Unbox a) => (a -> Bool) -> Vector a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (Unbox a) => (a -> Bool) -> Vector a -> Maybe Int -- | Yield the indices of elements satisfying the predicate findIndices :: (Unbox a) => (a -> Bool) -> Vector a -> Vector Int -- | Yield Just the index of the first occurence of the given -- element or Nothing if the vector does not contain the element elemIndex :: (Unbox a, Eq a) => a -> Vector a -> Maybe Int -- | Yield the indices of all occurences of the given element elemIndices :: (Unbox a, Eq a) => a -> Vector a -> Vector Int -- | Left fold foldl :: (Unbox b) => (a -> b -> a) -> a -> Vector b -> a -- | Lefgt fold on non-empty vectors foldl1 :: (Unbox a) => (a -> a -> a) -> Vector a -> a -- | Left fold with strict accumulator foldl' :: (Unbox b) => (a -> b -> a) -> a -> Vector b -> a -- | Left fold on non-empty vectors with strict accumulator foldl1' :: (Unbox a) => (a -> a -> a) -> Vector a -> a -- | Right fold foldr :: (Unbox a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors foldr1 :: (Unbox a) => (a -> a -> a) -> Vector a -> a -- | Right fold with a strict accumulator foldr' :: (Unbox a) => (a -> b -> b) -> b -> Vector a -> b -- | Right fold on non-empty vectors with strict accumulator foldr1' :: (Unbox a) => (a -> a -> a) -> Vector a -> a -- | Left fold (function applied to each element and its index) ifoldl :: (Unbox b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Left fold with strict accumulator (function applied to each element -- and its index) ifoldl' :: (Unbox b) => (a -> Int -> b -> a) -> a -> Vector b -> a -- | Right fold (function applied to each element and its index) ifoldr :: (Unbox a) => (Int -> a -> b -> b) -> b -> Vector a -> b -- | Right fold with strict accumulator (function applied to each element -- and its index) ifoldr' :: (Unbox a) => (Int -> a -> b -> b) -> b -> Vector a -> b all :: (Unbox a) => (a -> Bool) -> Vector a -> Bool any :: (Unbox a) => (a -> Bool) -> Vector a -> Bool and :: Vector Bool -> Bool or :: Vector Bool -> Bool sum :: (Unbox a, Num a) => Vector a -> a product :: (Unbox a, Num a) => Vector a -> a maximum :: (Unbox a, Ord a) => Vector a -> a maximumBy :: (Unbox a) => (a -> a -> Ordering) -> Vector a -> a minimum :: (Unbox a, Ord a) => Vector a -> a minimumBy :: (Unbox a) => (a -> a -> Ordering) -> Vector a -> a minIndex :: (Unbox a, Ord a) => Vector a -> Int minIndexBy :: (Unbox a) => (a -> a -> Ordering) -> Vector a -> Int maxIndex :: (Unbox a, Ord a) => Vector a -> Int maxIndexBy :: (Unbox a) => (a -> a -> Ordering) -> Vector a -> Int -- | The unfoldr function is a `dual' to foldr: while -- foldr reduces a vector to a summary value, unfoldr -- builds a list from a seed value. The function takes the element and -- returns Nothing if it is done generating the vector or returns -- Just (a,b), in which case, a is a prepended -- to the vector and b is used as the next element in a -- recursive call. -- -- A simple use of unfoldr: -- --
-- unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfoldr :: (Unbox a) => (b -> Maybe (a, b)) -> b -> Vector a -- | Unfold at most n elements unfoldrN :: (Unbox a) => Int -> (b -> Maybe (a, b)) -> b -> Vector a -- | Prefix scan prescanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Prefix scan with strict accumulator prescanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan postscanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan with strict accumulator postscanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan scanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan with strict accumulator scanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a -- | Scan over a non-empty Vector scanl1 :: (Unbox a) => (a -> a -> a) -> Vector a -> Vector a -- | Scan over a non-empty Vector with a strict accumulator scanl1' :: (Unbox a) => (a -> a -> a) -> Vector a -> Vector a -- | Prefix right-to-left scan prescanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Prefix right-to-left scan with strict accumulator prescanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan postscanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan with strict accumulator postscanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan scanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan with strict accumulator scanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b -- | Right-to-left scan over a non-empty vector scanr1 :: (Unbox a) => (a -> a -> a) -> Vector a -> Vector a -- | Right-to-left scan over a non-empty vector with a strict accumulator scanr1' :: (Unbox a) => (a -> a -> a) -> Vector a -> Vector a -- | Yield a vector of the given length containing the values x, -- x+1 etc. This operation is usually more efficient than -- enumFromTo. enumFromN :: (Unbox a, Num a) => a -> Int -> Vector a -- | Yield a vector of the given length containing the values x, -- x+y, x+y+y etc. This operations is usually more -- efficient than enumFromThenTo. enumFromStepN :: (Unbox a, Num a) => a -> a -> Int -> Vector a -- | Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (Unbox a, Enum a) => a -> a -> Vector a -- | Enumerate values from x to y with a specific step -- z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (Unbox a, Enum a) => a -> a -> a -> Vector a -- | Convert a vector to a list toList :: (Unbox a) => Vector a -> [a] -- | Convert a list to a vector fromList :: (Unbox a) => [a] -> Vector a -- | Convert the first n elements of a list to a vector -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: (Unbox a) => Int -> [a] -> Vector a -- | Perform the monadic action the given number of times and store the -- results in a vector. replicateM :: (Monad m, Unbox a) => Int -> m a -> m (Vector a) -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results mapM :: (Monad m, Unbox a, Unbox b) => (a -> m b) -> Vector a -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results mapM_ :: (Monad m, Unbox a) => (a -> m b) -> Vector a -> m () -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results forM :: (Monad m, Unbox a, Unbox b) => Vector a -> (a -> m b) -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results forM_ :: (Monad m, Unbox a) => Vector a -> (a -> m b) -> m () -- | Zip the two vectors with the monadic action and yield a vector of -- results zipWithM :: (Monad m, Unbox a, Unbox b, Unbox c) => (a -> b -> m c) -> Vector a -> Vector b -> m (Vector c) -- | Zip the two vectors with the monadic action and ignore the results zipWithM_ :: (Monad m, Unbox a, Unbox b) => (a -> b -> m c) -> Vector a -> Vector b -> m () -- | Drop elements that do not satisfy the monadic predicate filterM :: (Monad m, Unbox a) => (a -> m Bool) -> Vector a -> m (Vector a) -- | Monadic fold foldM :: (Monad m, Unbox b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m, Unbox b) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold over non-empty vectors fold1M :: (Monad m, Unbox a) => (a -> a -> m a) -> Vector a -> m a -- | Monad fold over non-empty vectors with strict accumulator fold1M' :: (Monad m, Unbox a) => (a -> a -> m a) -> Vector a -> m a -- | Destructively initialise a vector. create :: (Unbox a) => (forall s. ST s (MVector s a)) -> Vector a -- | Apply a destructive operation to a vector. The operation is applied to -- a copy of the vector unless it can be safely performed in place. modify :: (Unbox a) => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. copy :: (Unbox a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. This is not checked. unsafeCopy :: (Unbox a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () instance (Show a, Unbox a) => Show (Vector a) instance (Unbox a, Ord a) => Ord (Vector a) instance (Unbox a, Eq a) => Eq (Vector a) -- | Mutable adaptive unboxed vectors module Data.Vector.Unboxed.Mutable type IOVector = MVector RealWorld type STVector s = MVector s class (Vector Vector a, MVector MVector a) => Unbox a -- | Length of the mutable vector. length :: (Unbox a) => MVector s a -> Int overlaps :: (Unbox a) => MVector s a -> MVector s a -> Bool -- | Yield a part of the mutable vector without copying it. slice :: (Unbox a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. new :: (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. newWith :: (PrimMonad m, Unbox a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. read :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. write :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> m () -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive. grow :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) zip :: (Unbox a, Unbox b) => MVector s a -> MVector s b -> MVector s (a, b) zip3 :: (Unbox a, Unbox b, Unbox c) => MVector s a -> MVector s b -> MVector s c -> MVector s (a, b, c) zip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => MVector s a -> MVector s b -> MVector s c -> MVector s d -> MVector s (a, b, c, d) zip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => MVector s a -> MVector s b -> MVector s c -> MVector s d -> MVector s e -> MVector s (a, b, c, d, e) zip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => MVector s a -> MVector s b -> MVector s c -> MVector s d -> MVector s e -> MVector s f -> MVector s (a, b, c, d, e, f) unzip :: (Unbox a, Unbox b) => MVector s (a, b) -> (MVector s a, MVector s b) unzip3 :: (Unbox a, Unbox b, Unbox c) => MVector s (a, b, c) -> (MVector s a, MVector s b, MVector s c) unzip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => MVector s (a, b, c, d) -> (MVector s a, MVector s b, MVector s c, MVector s d) unzip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => MVector s (a, b, c, d, e) -> (MVector s a, MVector s b, MVector s c, MVector s d, MVector s e) unzip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => MVector s (a, b, c, d, e, f) -> (MVector s a, MVector s b, MVector s c, MVector s d, MVector s e, MVector s f) -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: (Unbox a) => Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. The length is not checked. unsafeNewWith :: (PrimMonad m, Unbox a) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. No bounds checks are -- performed. unsafeSwap :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive but this is not checked. unsafeGrow :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) -- | Mutable boxed vectors. module Data.Vector.Mutable -- | Mutable boxed vectors keyed on the monad they live in (IO or -- ST s). data MVector s a MVector :: !!Int -> !!Int -> !!MutableArray s a -> MVector s a type IOVector = MVector RealWorld type STVector s = MVector s -- | Length of the mutable vector. length :: MVector s a -> Int overlaps :: MVector s a -> MVector s a -> Bool -- | Yield a part of the mutable vector without copying it. slice :: Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. new :: (PrimMonad m) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. newWith :: (PrimMonad m) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. read :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. write :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m () -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (PrimMonad m) => MVector (PrimState m) a -> m () -- | Set all elements of the vector to the given value. set :: (PrimMonad m) => MVector (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (PrimMonad m) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive. grow :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: Int -> Int -> MVector s a -> MVector s a -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (PrimMonad m) => Int -> m (MVector (PrimState m) a) -- | Create a mutable vector of the given length and fill it with an -- initial value. The length is not checked. unsafeNewWith :: (PrimMonad m) => Int -> a -> m (MVector (PrimState m) a) -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (PrimMonad m) => MVector (PrimState m) a -> MVector (PrimState m) a -> m () -- | Grow a vector by the given number of elements. The number must be -- positive but this is not checked. unsafeGrow :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a) instance Typeable2 MVector instance MVector MVector a -- | A library for boxed vectors (that is, polymorphic arrays capable of -- holding any Haskell value). The vectors come in two flavors: -- --
-- unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 -- [10,9,8,7,6,5,4,3,2,1] --unfoldr :: (b -> Maybe (a, b)) -> b -> Vector a -- | Unfold at most n elements unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Vector a -- | Prefix scan prescanl :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Prefix scan with strict accumulator prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan postscanl :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Suffix scan with strict accumulator postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan function. scanl :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Haskell-style scan with strict accumulator scanl' :: (a -> b -> a) -> a -> Vector b -> Vector a -- | Scan over a non-empty Vector scanl1 :: (a -> a -> a) -> Vector a -> Vector a -- | Scan over a non-empty Vector with a strict accumulator scanl1' :: (a -> a -> a) -> Vector a -> Vector a -- | Prefix right-to-left scan prescanr :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Prefix right-to-left scan with strict accumulator prescanr' :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan postscanr :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Suffix right-to-left scan with strict accumulator postscanr' :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan scanr :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Haskell-style right-to-left scan with strict accumulator scanr' :: (a -> b -> b) -> b -> Vector a -> Vector b -- | Right-to-left scan over a non-empty vector scanr1 :: (a -> a -> a) -> Vector a -> Vector a -- | Right-to-left scan over a non-empty vector with a strict accumulator scanr1' :: (a -> a -> a) -> Vector a -> Vector a -- | Yield a vector of the given length containing the values x, -- x+1 etc. This operation is usually more efficient than -- enumFromTo. enumFromN :: (Num a) => a -> Int -> Vector a -- | Yield a vector of the given length containing the values x, -- x+y, x+y+y etc. This operations is usually more -- efficient than enumFromThenTo. enumFromStepN :: (Num a) => a -> a -> Int -> Vector a -- | Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (Enum a) => a -> a -> Vector a -- | Enumerate values from x to y with a specific step -- z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (Enum a) => a -> a -> a -> Vector a -- | Convert a vector to a list toList :: Vector a -> [a] -- | Convert a list to a vector fromList :: [a] -> Vector a -- | Convert the first n elements of a list to a vector -- --
-- fromListN n xs = fromList (take n xs) --fromListN :: Int -> [a] -> Vector a -- | Perform the monadic action the given number of times and store the -- results in a vector. replicateM :: (Monad m) => Int -> m a -> m (Vector a) -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results mapM :: (Monad m) => (a -> m b) -> Vector a -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results mapM_ :: (Monad m) => (a -> m b) -> Vector a -> m () -- | Apply the monadic action to all elements of the vector, yielding a -- vector of results forM :: (Monad m) => Vector a -> (a -> m b) -> m (Vector b) -- | Apply the monadic action to all elements of a vector and ignore the -- results forM_ :: (Monad m) => Vector a -> (a -> m b) -> m () -- | Zip the two vectors with the monadic action and yield a vector of -- results zipWithM :: (Monad m) => (a -> b -> m c) -> Vector a -> Vector b -> m (Vector c) -- | Zip the two vectors with the monadic action and ignore the results zipWithM_ :: (Monad m) => (a -> b -> m c) -> Vector a -> Vector b -> m () -- | Drop elements that do not satisfy the monadic predicate filterM :: (Monad m) => (a -> m Bool) -> Vector a -> m (Vector a) -- | Monadic fold foldM :: (Monad m) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold with strict accumulator foldM' :: (Monad m) => (a -> b -> m a) -> a -> Vector b -> m a -- | Monadic fold over non-empty vectors fold1M :: (Monad m) => (a -> a -> m a) -> Vector a -> m a -- | Monad fold over non-empty vectors with strict accumulator fold1M' :: (Monad m) => (a -> a -> m a) -> Vector a -> m a -- | Destructively initialise a vector. create :: (forall s. ST s (MVector s a)) -> Vector a -- | Apply a destructive operation to a vector. The operation is applied to -- a copy of the vector unless it can be safely performed in place. modify :: (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. copy :: (PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () -- | Copy an immutable vector into a mutable one. The two vectors must have -- the same length. This is not checked. unsafeCopy :: (PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () instance Typeable1 Vector instance (Ord a) => Ord (Vector a) instance (Eq a) => Eq (Vector a) instance Vector Vector a instance (Data a) => Data (Vector a) instance (Show a) => Show (Vector a)