-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Size tagged vectors -- -- Please see README.md @package vector-sized @version 1.0.0.0 module Data.Vector.Generic.Mutable.Sized.Internal -- | A wrapper to tag mutable vectors with a type level length. -- -- Be careful when using the constructor here to not construct sized -- vectors which have a different length than that specified in the type -- parameter! newtype MVector v (n :: Nat) s a MVector :: (v s a) -> MVector v s a instance Control.DeepSeq.NFData (v s a) => Control.DeepSeq.NFData (Data.Vector.Generic.Mutable.Sized.Internal.MVector v n s a) instance Foreign.Storable.Storable (v s a) => Foreign.Storable.Storable (Data.Vector.Generic.Mutable.Sized.Internal.MVector v n s a) instance (Data.Data.Data (v s a), Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable s, Data.Typeable.Internal.Typeable v, GHC.TypeNats.KnownNat n) => Data.Data.Data (Data.Vector.Generic.Mutable.Sized.Internal.MVector v n s a) instance GHC.Generics.Generic (Data.Vector.Generic.Mutable.Sized.Internal.MVector v n s a) -- | This module reexports the functionality in Mutable which maps -- well to explicity sized vectors. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Generic.Mutable.Sized -- | A wrapper to tag mutable vectors with a type level length. -- -- Be careful when using the constructor here to not construct sized -- vectors which have a different length than that specified in the type -- parameter! data MVector v (n :: Nat) s a -- | O(1) Yield the length of the mutable vector as an Int. length :: forall v n s a. (KnownNat n) => MVector v n s a -> Int -- | O(1) Yield the length of the mutable vector as a Proxy. length' :: forall v n s a. (KnownNat n) => MVector v n s a -> Proxy n -- | O(1) Check whether the mutable vector is empty null :: forall v n s a. (KnownNat n) => MVector v n s a -> Bool -- | O(1) Yield a slice of the mutable vector without copying it -- with an inferred length argument. slice :: forall v i n k s a p. (KnownNat i, KnownNat n, KnownNat k, MVector v a) => p i -> MVector v ((i + n) + k) s a -> MVector v n s a -- | O(1) Yield a slice of the mutable vector without copying it -- with an explicit length argument. slice' :: forall v i n k s a p. (KnownNat i, KnownNat n, KnownNat k, MVector v a) => p i -> p n -> MVector v ((i + n) + k) s a -> MVector v n s a -- | O(1) Yield all but the last element of a non-empty mutable -- vector without copying. init :: forall v n s a. (MVector v a) => MVector v (n + 1) s a -> MVector v n s a -- | O(1) Yield all but the first element of a non-empty mutable -- vector without copying. tail :: forall v n s a. (MVector v a) => MVector v (1 + n) s a -> MVector v n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall v n k s a. (KnownNat n, KnownNat k, MVector v a) => MVector v (n + k) s a -> MVector v n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall v n k s a p. (KnownNat n, KnownNat k, MVector v a) => p n -> MVector v (n + k) s a -> MVector v n s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall v n k s a. (KnownNat n, KnownNat k, MVector v a) => MVector v (n + k) s a -> MVector v k s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall v n k s a p. (KnownNat n, KnownNat k, MVector v a) => p n -> MVector v (n + k) s a -> MVector v k s a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall v n m s a. (KnownNat n, KnownNat m, MVector v a) => MVector v (n + m) s a -> (MVector v n s a, MVector v m s a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall v n m s a p. (KnownNat n, KnownNat m, MVector v a) => p n -> MVector v (n + m) s a -> (MVector v n s a, MVector v m s a) -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. overlaps :: forall v n k s a. (KnownNat n, KnownNat k, MVector v a) => MVector v n s a -> MVector v k s a -> Bool -- | Create a mutable vector where the length is inferred from the type. new :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => m (MVector v n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type. -- The memory is not initialized. unsafeNew :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => m (MVector v n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with an initial value. replicate :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => a -> m (MVector v n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with an initial value. replicate' :: forall v n m a p. (KnownNat n, PrimMonad m, MVector v a) => p n -> a -> m (MVector v n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with values produced by repeatedly executing the monadic -- action. replicateM :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => m a -> m (MVector v n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with values produced by repeatedly -- executing the monadic action. replicateM' :: forall v n m a p. (KnownNat n, PrimMonad m, MVector v a) => p n -> m a -> m (MVector v n (PrimState m) a) -- | Create a copy of a mutable vector. clone :: forall v n m a. (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> m (MVector v n (PrimState m) a) -- | Grow a mutable vector by an amount given explicitly as a Proxy -- argument. grow :: forall v n k m a p. (KnownNat k, PrimMonad m, MVector v a) => p k -> MVector v n (PrimState m) a -> m (MVector v (n + k) (PrimState m) a) -- | Grow a mutable vector (from the front) by an amount given explicitly -- as a Proxy argument. growFront :: forall v n k m a p. (KnownNat k, PrimMonad m, MVector v a) => p k -> MVector v n (PrimState m) a -> m (MVector v (n + k) (PrimState m) a) -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. clear :: (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> m () -- | O(1) Yield the element at a given type-safe position using -- Finite. read :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Finite n -> m a -- | O(1) Yield the element at a given type-safe position using -- Proxy. read' :: forall v n k a m p. (KnownNat n, KnownNat k, PrimMonad m, MVector v a) => MVector v ((n + k) + 1) (PrimState m) a -> p k -> m a -- | O(1) Replace the element at a given type-safe position using -- Finite. write :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Finite n -> a -> m () -- | O(1) Replace the element at a given type-safe position using -- Proxy. write' :: forall v n k a m p. (KnownNat n, KnownNat k, PrimMonad m, MVector v a) => MVector v ((n + k) + 1) (PrimState m) a -> p k -> a -> m () -- | O(1) Modify the element at a given type-safe position using -- Finite. modify :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> (a -> a) -> Finite n -> m () -- | O(1) Modify the element at a given type-safe position using -- Proxy. modify' :: forall v n k a m p. (KnownNat n, KnownNat k, PrimMonad m, MVector v a) => MVector v ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at a given type-safe position using -- Finites. swap :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Finite n -> Finite n -> m () -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Finite n -> a -> m a -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange' :: forall v n k a m p. (KnownNat n, KnownNat k, PrimMonad m, MVector v a) => MVector v ((n + k) + 1) (PrimState m) a -> p k -> a -> m a -- | O(1) Yield the element at a given Int position without -- bounds checking. unsafeRead :: forall v n a m. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Int -> m a -- | O(1) Replace the element at a given Int position without -- bounds checking. unsafeWrite :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Int -> a -> m () -- | O(1) Modify the element at a given Int position without -- bounds checking. unsafeModify :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at a given Int position without -- bounds checking. unsafeSwap :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Int -> Int -> m () -- | O(1) Replace the element at a given Int position and -- return the old element. No bounds checks are performed. unsafeExchange :: forall v n m a. (KnownNat n, PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Int -> a -> m a -- | Compute the next (lexicographically) permutation of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall v n e m. (KnownNat n, Ord e, PrimMonad m, MVector v e) => MVector v n (PrimState m) e -> m Bool -- | Set all elements of the vector to the given value. set :: (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors may not overlap. copy :: (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m () -- | Move the contents of a vector. If the two vectors do not overlap, this -- is equivalent to copy. Otherwise, the copying is performed as -- if the source vector were copied to a temporary vector and then the -- temporary vector was copied to the target vector. move :: (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m () -- | Copy a vector. The two vectors may not overlap. This is not checked. unsafeCopy :: (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> MVector v n (PrimState m) a -> m () -- | Convert a MVector into a MVector if it has the correct -- size, otherwise return Nothing. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. toSized :: forall v n s a. (MVector v a, KnownNat n) => v s a -> Maybe (MVector v n s a) -- | Takes a MVector and returns a continuation providing a -- MVector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a MVector into a MVector with the -- correct size parameter n. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. withSized :: forall v s a r. MVector v a => v s a -> (forall n. KnownNat n => MVector v n s a -> r) -> r -- | Convert a MVector into a MVector. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. fromSized :: MVector v n s a -> v s a module Data.Vector.Generic.Sized.Internal -- | A wrapper to tag vectors with a type level length. -- -- Be careful when using the constructor here to not construct sized -- vectors which have a different length than that specified in the type -- parameter! newtype Vector v (n :: Nat) a Vector :: (v a) -> Vector v a instance (Data.Data.Data (v a), Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable v, GHC.TypeNats.KnownNat n) => Data.Data.Data (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Data.Functor.Classes.Ord1 v => Data.Functor.Classes.Ord1 (Data.Vector.Generic.Sized.Internal.Vector v n) instance Data.Functor.Classes.Eq1 v => Data.Functor.Classes.Eq1 (Data.Vector.Generic.Sized.Internal.Vector v n) instance Data.Functor.Classes.Show1 v => Data.Functor.Classes.Show1 (Data.Vector.Generic.Sized.Internal.Vector v n) instance GHC.Generics.Generic (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Control.DeepSeq.NFData (v a) => Control.DeepSeq.NFData (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Data.Traversable.Traversable v => Data.Traversable.Traversable (Data.Vector.Generic.Sized.Internal.Vector v n) instance Data.Foldable.Foldable v => Data.Foldable.Foldable (Data.Vector.Generic.Sized.Internal.Vector v n) instance GHC.Base.Functor v => GHC.Base.Functor (Data.Vector.Generic.Sized.Internal.Vector v n) instance GHC.Classes.Ord (v a) => GHC.Classes.Ord (Data.Vector.Generic.Sized.Internal.Vector v n a) instance GHC.Classes.Eq (v a) => GHC.Classes.Eq (Data.Vector.Generic.Sized.Internal.Vector v n a) instance GHC.Show.Show (v a) => GHC.Show.Show (Data.Vector.Generic.Sized.Internal.Vector v n a) -- | This module reexports the functionality in Generic which maps -- well to explicity sized vectors. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Generic.Sized -- | A wrapper to tag vectors with a type level length. -- -- Be careful when using the constructor here to not construct sized -- vectors which have a different length than that specified in the type -- parameter! data Vector v (n :: Nat) a -- | A wrapper to tag mutable vectors with a type level length. -- -- Be careful when using the constructor here to not construct sized -- vectors which have a different length than that specified in the type -- parameter! data MVector v (n :: Nat) s a -- | O(1) Yield the length of the vector as an Int. This is -- more like natVal than length, extracting the value from -- the KnownNat instance and not looking at the vector itself. length :: forall v n a. KnownNat n => Vector v n a -> Int -- | O(1) Yield the length of the vector as a Proxy. This -- function doesn't do anything; it merely allows the size -- parameter of the vector to be passed around as a Proxy. length' :: forall v n a. Vector v n a -> Proxy n -- | O(1) Reveal a KnownNat instance for a vector's length, -- determined at runtime. knownLength :: forall v n a r. Vector v a => Vector v n a -> (KnownNat n => r) -> r -- | O(1) Reveal a KnownNat instance and Proxy for a -- vector's length, determined at runtime. knownLength' :: forall v n a r. Vector v a => Vector v n a -> (KnownNat n => Proxy n -> r) -> r -- | O(1) Safe indexing using a Finite. index :: forall v n a. (KnownNat n, Vector v a) => Vector v n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall v n m a p. (KnownNat n, KnownNat m, Vector v a) => Vector v ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall v n a. (KnownNat n, Vector v a) => Vector v n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall v n a. (Vector v a) => Vector v (1 + n) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall v n a. (Vector v a) => Vector v (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall v n k a m p. (KnownNat n, KnownNat k, Vector v a, Monad m) => Vector v (n + k) a -> p n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v (1 + n) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall v n a m. (KnownNat n, Vector v a, Monad m) => Vector v (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall v i n m a p. (KnownNat i, KnownNat n, KnownNat m, Vector v a) => p i -> Vector v ((i + n) + m) a -> Vector v n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall v i n m a p. (KnownNat i, KnownNat n, KnownNat m, Vector v a) => p i -> p n -> Vector v ((i + n) + m) a -> Vector v n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall v n a. (Vector v a) => Vector v (n + 1) a -> Vector v n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall v n a. (Vector v a) => Vector v (1 + n) a -> Vector v n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (n + m) a -> Vector v n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall v n m a p. (KnownNat n, KnownNat m, Vector v a) => p n -> Vector v (n + m) a -> Vector v n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (n + m) a -> Vector v m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall v n m a p. (KnownNat n, KnownNat m, Vector v a) => p n -> Vector v (n + m) a -> Vector v m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall v n m a. (KnownNat n, KnownNat m, Vector v a) => Vector v (n + m) a -> (Vector v n a, Vector v m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall v n m a p. (KnownNat n, KnownNat m, Vector v a) => p n -> Vector v (n + m) a -> (Vector v n a, Vector v m a) -- | O(1) Empty vector. empty :: forall v a. (Vector v a) => Vector v 0 a -- | O(1) Vector with exactly one element. singleton :: forall v a. (Vector v a) => a -> Vector v 1 a -- | O(n) Construct a vector in a type safe manner fromTuple (1,2) -- :: Vector v 2 Int fromTuple ("hey", "what's", "going", "on") :: Vector -- v 4 String fromTuple :: forall v a input length. (Vector v a, IndexedListLiterals input length a, KnownNat length) => input -> Vector v length a -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall v n a. (KnownNat n, Vector v a) => a -> Vector v n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall v n a p. (KnownNat n, Vector v a) => p n -> a -> Vector v n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall v n a. (KnownNat n, Vector v a) => (Finite n -> a) -> Vector v n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall v n a p. (KnownNat n, Vector v a) => p n -> (Finite n -> a) -> Vector v n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall v n a. (KnownNat n, Vector v a) => (a -> a) -> a -> Vector v n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall v n a p. (KnownNat n, Vector v a) => p n -> (a -> a) -> a -> Vector v n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall v n m a. (KnownNat n, Vector v a, Monad m) => m a -> m (Vector v n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall v n m a p. (KnownNat n, Vector v a, Monad m) => p n -> m a -> m (Vector v n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall v n m a. (KnownNat n, Vector v a, Monad m) => (Finite n -> m a) -> m (Vector v n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall v n m a p. (KnownNat n, Vector v a, Monad m) => p n -> (Finite n -> m a) -> m (Vector v n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall v n a b. (KnownNat n, Vector v a) => (b -> (a, b)) -> b -> Vector v n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall v n a b p. (KnownNat n, Vector v a) => p n -> (b -> (a, b)) -> b -> Vector v n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> Vector v n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall v n a p. (KnownNat n, Vector v a, Num a) => a -> p n -> Vector v n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall v n a. (KnownNat n, Vector v a, Num a) => a -> a -> Vector v n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall v n a p. (KnownNat n, Vector v a, Num a) => a -> a -> p n -> Vector v n a -- | O(n) Prepend an element. cons :: forall v n a. Vector v a => a -> Vector v n a -> Vector v (1 + n) a -- | O(n) Append an element. snoc :: forall v n a. Vector v a => Vector v n a -> a -> Vector v (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall v n m a. Vector v a => Vector v n a -> Vector v m a -> Vector v (n + m) a -- | O(n) Yield the argument but force it not to retain any extra -- memory, possibly by copying it. -- -- This is especially useful when dealing with slices. For example: -- --
-- force (slice 0 2 <huge vector>) ---- -- Here, the slice retains a reference to the huge vector. Forcing it -- creates a copy of just the elements that belong to the slice and -- allows the huge vector to be garbage collected. force :: Vector v a => Vector v n a -> Vector v n a -- | O(m+n) For each pair (i,a) from the list, replace the -- vector element at position i by a. -- --
-- <5,9,2,7> // [(2,1),(0,3),(2,8)] = <3,9,8,7> --(//) :: (Vector v a) => Vector v m a -> [(Finite m, a)] -> Vector v m a -- | O(m+n) For each pair (i,a) from the vector of -- index/value pairs, replace the vector element at position i -- by a. -- --
-- update <5,9,2,7> <(2,1),(0,3),(2,8)> = <3,9,8,7> --update :: (Vector v a, Vector v (Int, a)) => Vector v m a -> Vector v n (Int, a) -> Vector v m a -- | O(m+n) For each index i from the index vector and the -- corresponding value a from the value vector, replace the -- element of the initial vector at position i by a. -- --
-- update_ <5,9,2,7> <2,0,2> <1,3,8> = <3,9,8,7> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -> Vector v m a -- | Same as (//) but without bounds checking. unsafeUpd :: (Vector v a) => Vector v m a -> [(Int, a)] -> Vector v m a -- | Same as update but without bounds checking. unsafeUpdate :: (Vector v a, Vector v (Int, a)) => Vector v m a -> Vector v n (Int, a) -> Vector v m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -> Vector v m a -- | O(m+n) For each pair (i,b) from the list, replace the -- vector element a at position i by f a b. -- --
-- accum (+) <5,9,2> [(2,4),(1,6),(0,3),(1,7)] = <5+3, 9+6+7, 2+4> --accum :: Vector v a => (a -> b -> a) -> Vector v m a -> [(Int, b)] -> Vector v m a -- | O(m+n) For each pair (i,b) from the vector of pairs, -- replace the vector element a at position i by f -- a b. -- --
-- accumulate (+) <5,9,2> <(2,4),(1,6),(0,3),(1,7)> = <5+3, 9+6+7, 2+4> --accumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> Vector v m a -> Vector v n (Int, b) -> Vector v m a -- | O(m+n) For each index i from the index vector and the -- corresponding value b from the the value vector, replace the -- element of the initial vector at position i by f a -- b. -- --
-- accumulate_ (+) <5,9,2> <2,1,0,1> <4,6,3,7> = <5+3, 9+6+7, 2+4> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> Vector v m a -> Vector v n Int -> Vector v n b -> Vector v m a -- | Same as accum but without bounds checking. unsafeAccum :: Vector v a => (a -> b -> a) -> Vector v m a -> [(Int, b)] -> Vector v m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> Vector v m a -> Vector v n (Int, b) -> Vector v m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> Vector v m a -> Vector v n Int -> Vector v n b -> Vector v m a -- | O(n) Reverse a vector reverse :: (Vector v a) => Vector v n a -> Vector v n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: (Vector v a, Vector v Int) => Vector v m a -> Vector v n Int -> Vector v n a -- | Lens to access (O(1)) and update (O(n)) an arbitrary -- element by its index. ix :: forall v n a f. (KnownNat n, Vector v a, Functor f) => Finite n -> (a -> f a) -> Vector v n a -> f (Vector v n a) -- | Lens to access (O(1)) and update (O(n)) the first -- element of a non-empty vector. _head :: forall v n a f. (KnownNat n, Vector v a, Functor f) => (a -> f a) -> Vector v (1 + n) a -> f (Vector v (1 + n) a) -- | Lens to access (O(1)) and update (O(n)) the last element -- of a non-empty vector. _last :: forall v n a f. (KnownNat n, Vector v a, Functor f) => (a -> f a) -> Vector v (n + 1) a -> f (Vector v (n + 1) a) -- | O(n) Pair each element in a vector with its index indexed :: (Vector v a, Vector v (Int, a), Vector v (Finite n, a)) => Vector v n a -> Vector v n (Finite n, a) -- | O(n) Map a function over a vector map :: (Vector v a, Vector v b) => (a -> b) -> Vector v n a -> Vector v n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Vector v a, Vector v b) => (Finite n -> a -> b) -> Vector v n a -> Vector v n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (Vector v a, Vector v b) => (a -> Vector v m b) -> Vector v n a -> Vector v (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: (Monad m, Vector v a, Vector v b) => (a -> m b) -> Vector v n a -> m (Vector v n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: (Monad m, Vector v a, Vector v b) => (Finite n -> a -> m b) -> Vector v n a -> m (Vector v n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: (Monad m, Vector v a) => (a -> m b) -> Vector v n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: (Monad m, Vector v a) => (Finite n -> a -> m b) -> Vector v n a -> m () -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results. Equvalent to flip mapM. forM :: (Monad m, Vector v a, Vector v b) => Vector v n a -> (a -> m b) -> m (Vector v n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: (Monad m, Vector v a) => Vector v n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Vector v n a -> Vector v n b -> Vector v n c -- | Zip three vectors with the given function. zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d zipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (a -> b -> c -> d -> e) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e zipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => (a -> b -> c -> d -> e -> f) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f zipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => (a -> b -> c -> d -> e -> f -> g) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Vector v a, Vector v b, Vector v c) => (Finite n -> a -> b -> c) -> Vector v n a -> Vector v n b -> Vector v n c izipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (Finite n -> a -> b -> c -> d) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d izipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (Finite n -> a -> b -> c -> d -> e) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e izipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => (Finite n -> a -> b -> c -> d -> e -> f) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f izipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => (Finite n -> a -> b -> c -> d -> e -> f -> g) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n g -- | O(n) Zip two vectors of the same length zip :: (Vector v a, Vector v b, Vector v (a, b)) => Vector v n a -> Vector v n b -> Vector v n (a, b) zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n (a, b, c) zip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n (a, b, c, d) zip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n (a, b, c, d, e) zip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d -> Vector v n e -> Vector v n f -> Vector v n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: (Monad m, Vector v a, Vector v b, Vector v c) => (a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: (Monad m, Vector v a, Vector v b, Vector v c) => (Finite n -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: (Monad m, Vector v a, Vector v b) => (a -> b -> m c) -> Vector v n a -> Vector v n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: (Monad m, Vector v a, Vector v b) => (Finite n -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: (Vector v a, Vector v b, Vector v (a, b)) => Vector v n (a, b) -> (Vector v n a, Vector v n b) unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Vector v n (a, b, c) -> (Vector v n a, Vector v n b, Vector v n c) unzip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Vector v n (a, b, c, d) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d) unzip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Vector v n (a, b, c, d, e) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e) unzip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Vector v n (a, b, c, d, e, f) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e, Vector v n f) -- | O(n) Check if the vector contains an element elem :: (Vector v a, Eq a) => a -> Vector v n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: (Vector v a, Eq a) => a -> Vector v n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: Vector v a => (a -> Bool) -> Vector v n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: Vector v a => (a -> Bool) -> Vector v n a -> Maybe (Finite n) -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Vector v a, Eq a) => a -> Vector v n a -> Maybe (Finite n) -- | O(n) Left fold foldl :: Vector v b => (a -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (1 + n) a -> a -- | O(n) Left fold with strict accumulator foldl' :: Vector v b => (a -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (1 + n) a -> a -- | O(n) Right fold foldr :: Vector v a => (a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: Vector v a => (a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: Vector v b => (a -> Finite n -> b -> a) -> a -> Vector v n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: Vector v b => (a -> Finite n -> b -> a) -> a -> Vector v n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: Vector v a => (Finite n -> a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: Vector v a => (Finite n -> a -> b -> b) -> b -> Vector v n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Vector v a => (a -> Bool) -> Vector v n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Vector v a => (a -> Bool) -> Vector v n a -> Bool -- | O(n) Check if all elements are True and :: Vector v Bool => Vector v n Bool -> Bool -- | O(n) Check if any element is True or :: Vector v Bool => Vector v n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Vector v a, Num a) => Vector v n a -> a -- | O(n) Compute the produce of the elements product :: (Vector v a, Num a) => Vector v n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Vector v a, Ord a, KnownNat n) => Vector v (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: (Vector v a, KnownNat n) => (a -> a -> Ordering) -> Vector v (n + 1) a -> Finite (n + 1) -- | O(n) Monadic fold foldM :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: (Monad m, Vector v b) => (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (1 + n) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: (Monad m, Vector v b) => (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: (Monad m, Vector v b) => (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: (Monad m, Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: (Monad m, Vector v b) => (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, Vector v a, KnownNat n) => (a -> a -> m a) -> Vector v (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: (Monad m, Vector v a, Vector v (m a)) => Vector v n (m a) -> m (Vector v n a) -- | Evaluate each action and discard the results sequence_ :: (Monad m, Vector v (m a)) => Vector v n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Prescan with strict accumulator prescanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan with strict accumulator postscanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Haskell-style scan scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a -- | O(n) Scan over a non-empty vector scanl1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan postscanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left Haskell-style scan scanr :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (Vector v a, Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: (Vector v a, KnownNat n) => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 1) a -- | O(n) Convert a vector to a list toList :: Vector v a => Vector v n a -> [a] -- | O(n) Convert a list to a vector fromList :: (Vector v a, KnownNat n) => [a] -> Maybe (Vector v n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall v n a. (Vector v a, KnownNat n) => [a] -> Maybe (Vector v n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall v n a p. (Vector v a, KnownNat n) => p n -> [a] -> Maybe (Vector v n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall v a r. Vector v a => [a] -> (forall n. KnownNat n => Vector v n a -> r) -> r -- | O(n) Convert different vector types convert :: (Vector v a, Vector w a) => Vector v n a -> Vector w n a -- | O(n) Yield an immutable copy of the mutable vector. freeze :: (PrimMonad m, Vector v a) => MVector (Mutable v) n (PrimState m) a -> m (Vector v n a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: (PrimMonad m, Vector v a) => Vector v n a -> m (MVector (Mutable v) n (PrimState m) a) -- | O(n) Copy an immutable vector into a mutable one. copy :: (PrimMonad m, Vector v a) => MVector (Mutable v) n (PrimState m) a -> Vector v n a -> m () -- | O(1) Unsafely convert a mutable vector to an immutable one -- withouy copying. The mutable vector may not be used after this -- operation. unsafeFreeze :: (PrimMonad m, Vector v a) => MVector (Mutable v) n (PrimState m) a -> m (Vector v n a) -- | O(n) Unsafely convert an immutable vector to a mutable one -- without copying. The immutable vector may not be used after this -- operation. unsafeThaw :: (PrimMonad m, Vector v a) => Vector v n a -> m (MVector (Mutable v) n (PrimState m) a) -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall v n a. (Vector v a, KnownNat n) => v a -> Maybe (Vector v n a) -- | Takes a Vector and returns a continuation providing a -- Sized with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall v a r. Vector v a => v a -> (forall n. KnownNat n => Vector v n a -> r) -> r fromSized :: Vector v n a -> v a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: forall a b v w (n :: Nat). (Vector v a, Vector w b) => (v a -> w b) -> Vector v n a -> Vector w n b instance (GHC.TypeNats.KnownNat n, Data.Vector.Generic.Base.Vector v a, GHC.Read.Read (v a)) => GHC.Read.Read (Data.Vector.Generic.Sized.Internal.Vector v n a) instance (GHC.TypeNats.KnownNat n, Foreign.Storable.Storable a, Data.Vector.Generic.Base.Vector v a) => Foreign.Storable.Storable (Data.Vector.Generic.Sized.Internal.Vector v n a) instance GHC.TypeNats.KnownNat n => GHC.Base.Applicative (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance (Data.Semigroup.Semigroup g, Data.Vector.Generic.Base.Vector v g) => Data.Semigroup.Semigroup (Data.Vector.Generic.Sized.Internal.Vector v n g) instance (GHC.Base.Monoid m, Data.Vector.Generic.Base.Vector v m, GHC.TypeNats.KnownNat n) => GHC.Base.Monoid (Data.Vector.Generic.Sized.Internal.Vector v n m) instance (Data.Vector.Generic.Base.Vector v a, GHC.Num.Num a, GHC.TypeNats.KnownNat n) => GHC.Num.Num (Data.Vector.Generic.Sized.Internal.Vector v n a) instance (Data.Vector.Generic.Base.Vector v a, GHC.Real.Fractional a, GHC.TypeNats.KnownNat n) => GHC.Real.Fractional (Data.Vector.Generic.Sized.Internal.Vector v n a) instance (Data.Vector.Generic.Base.Vector v a, GHC.Float.Floating a, GHC.TypeNats.KnownNat n) => GHC.Float.Floating (Data.Vector.Generic.Sized.Internal.Vector v n a) -- | This module re-exports the functionality in Sized specialized -- to Mutable -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Mutable.Sized -- | Vector specialized to use Mutable type MVector = MVector MVector -- | O(1) Yield the length of the mutable vector as an Int. length :: forall n s a. (KnownNat n) => MVector n s a -> Int -- | O(1) Yield the length of the mutable vector as a Proxy. length' :: forall n s a. (KnownNat n) => MVector n s a -> Proxy n -- | O(1) Check whether the mutable vector is empty null :: forall n s a. (KnownNat n) => MVector n s a -> Bool -- | O(1) Yield a slice of the mutable vector without copying it -- with an inferred length argument. slice :: forall i n k s a p. (KnownNat i, KnownNat n, KnownNat k) => p i -> MVector ((i + n) + k) s a -> MVector n s a -- | O(1) Yield a slice of the mutable vector without copying it -- with an explicit length argument. slice' :: forall i n k s a p. (KnownNat i, KnownNat n, KnownNat k) => p i -> p n -> MVector ((i + n) + k) s a -> MVector n s a -- | O(1) Yield all but the last element of a non-empty mutable -- vector without copying. init :: forall n s a. () => MVector (n + 1) s a -> MVector n s a -- | O(1) Yield all but the first element of a non-empty mutable -- vector without copying. tail :: forall n s a. () => MVector (1 + n) s a -> MVector n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n k s a. (KnownNat n, KnownNat k) => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n k s a p. (KnownNat n, KnownNat k) => p n -> MVector (n + k) s a -> MVector n s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n k s a. (KnownNat n, KnownNat k) => MVector (n + k) s a -> MVector k s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n k s a p. (KnownNat n, KnownNat k) => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m s a. (KnownNat n, KnownNat m) => MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. (KnownNat n, KnownNat m) => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. overlaps :: forall n k s a. (KnownNat n, KnownNat k) => MVector n s a -> MVector k s a -> Bool -- | Create a mutable vector where the length is inferred from the type. new :: forall n m a. (KnownNat n, PrimMonad m) => m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type. -- The memory is not initialized. unsafeNew :: forall n m a. (KnownNat n, PrimMonad m) => m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with an initial value. replicate :: forall n m a. (KnownNat n, PrimMonad m) => a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with an initial value. replicate' :: forall n m a p. (KnownNat n, PrimMonad m) => p n -> a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with values produced by repeatedly executing the monadic -- action. replicateM :: forall n m a. (KnownNat n, PrimMonad m) => m a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with values produced by repeatedly -- executing the monadic action. replicateM' :: forall n m a p. (KnownNat n, PrimMonad m) => p n -> m a -> m (MVector n (PrimState m) a) -- | Create a copy of a mutable vector. clone :: forall n m a. PrimMonad m => MVector n (PrimState m) a -> m (MVector n (PrimState m) a) -- | Grow a mutable vector by an amount given explicitly as a Proxy -- argument. grow :: forall n k m a p. (KnownNat k, PrimMonad m) => p k -> MVector n (PrimState m) a -> m (MVector (n + k) (PrimState m) a) -- | Grow a mutable vector (from the front) by an amount given explicitly -- as a Proxy argument. growFront :: forall n k m a p. (KnownNat k, PrimMonad m) => p k -> MVector n (PrimState m) a -> m (MVector (n + k) (PrimState m) a) -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. clear :: PrimMonad m => MVector n (PrimState m) a -> m () -- | O(1) Yield the element at a given type-safe position using -- Finite. read :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Finite n -> m a -- | O(1) Yield the element at a given type-safe position using -- Proxy. read' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m) => MVector ((n + k) + 1) (PrimState m) a -> p k -> m a -- | O(1) Replace the element at a given type-safe position using -- Finite. write :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Finite n -> a -> m () -- | O(1) Replace the element at a given type-safe position using -- Proxy. write' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m) => MVector ((n + k) + 1) (PrimState m) a -> p k -> a -> m () -- | O(1) Modify the element at a given type-safe position using -- Finite. modify :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> (a -> a) -> Finite n -> m () -- | O(1) Modify the element at a given type-safe position using -- Proxy. modify' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at a given type-safe position using -- Finites. swap :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Finite n -> Finite n -> m () -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Finite n -> a -> m a -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m) => MVector ((n + k) + 1) (PrimState m) a -> p k -> a -> m a -- | O(1) Yield the element at a given Int position without -- bounds checking. unsafeRead :: forall n a m. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Int -> m a -- | O(1) Replace the element at a given Int position without -- bounds checking. unsafeWrite :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Int -> a -> m () -- | O(1) Modify the element at a given Int position without -- bounds checking. unsafeModify :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at a given Int position without -- bounds checking. unsafeSwap :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Int -> Int -> m () -- | O(1) Replace the element at a given Int position and -- return the old element. No bounds checks are performed. unsafeExchange :: forall n m a. (KnownNat n, PrimMonad m) => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next (lexicographically) permutation of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (KnownNat n, Ord e, PrimMonad m) => MVector n (PrimState m) e -> m Bool -- | Set all elements of the vector to the given value. set :: PrimMonad m => MVector n (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors may not overlap. copy :: PrimMonad m => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Move the contents of a vector. If the two vectors do not overlap, this -- is equivalent to copy. Otherwise, the copying is performed as -- if the source vector were copied to a temporary vector and then the -- temporary vector was copied to the target vector. move :: PrimMonad m => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Copy a vector. The two vectors may not overlap. This is not checked. unsafeCopy :: PrimMonad m => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Convert a MVector into a MVector if it has the correct -- size, otherwise return Nothing. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. toSized :: forall n a s. KnownNat n => MVector s a -> Maybe (MVector n s a) -- | Takes a MVector and returns a continuation providing a -- MVector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a MVector into a MVector with the -- correct size parameter n. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. withSized :: forall s a r. () => MVector s a -> (forall n. KnownNat n => MVector n s a -> r) -> r -- | Convert a MVector into a MVector. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. fromSized :: MVector n s a -> MVector s a -- | This module re-exports the functionality in Sized specialized -- to Vector. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Sized -- | Vector specialized to use Vector type Vector = Vector Vector -- | Vector specialized to use Mutable type MVector = MVector MVector -- | O(1) Yield the length of the vector as an Int. This is -- more like natVal than length, extracting the value from -- the KnownNat instance and not looking at the vector itself. length :: forall n a. KnownNat n => Vector n a -> Int -- | O(1) Yield the length of the vector as a Proxy. This -- function doesn't do anything; it merely allows the size -- parameter of the vector to be passed around as a Proxy. length' :: forall n a. Vector n a -> Proxy n -- | O(1) Reveal a KnownNat instance for a vector's length, -- determined at runtime. knownLength :: forall n a r. Vector n a -> (KnownNat n => r) -> r -- | O(1) Reveal a KnownNat instance and Proxy for a -- vector's length, determined at runtime. knownLength' :: forall n a r. Vector n a -> (KnownNat n => Proxy n -> r) -> r -- | O(1) Safe indexing using a Finite. index :: forall n a. KnownNat n => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. (KnownNat n, KnownNat m) => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. KnownNat n => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. Vector (1 + n) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. Vector (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall n a m. (KnownNat n, Monad m) => Vector n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall n k a m p. (KnownNat n, KnownNat k, Monad m) => Vector (n + k) a -> p n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall n a m. (KnownNat n, Monad m) => Vector n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall n a m. (KnownNat n, Monad m) => Vector (1 + n) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall n a m. (KnownNat n, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall i n m a p. (KnownNat i, KnownNat n, KnownNat m) => p i -> Vector ((i + n) + m) a -> Vector n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall i n m a p. (KnownNat i, KnownNat n, KnownNat m) => p i -> p n -> Vector ((i + n) + m) a -> Vector n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall n a. Vector (n + 1) a -> Vector n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall n a. Vector (1 + n) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n m a. (KnownNat n, KnownNat m) => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n m a p. (KnownNat n, KnownNat m) => p n -> Vector (n + m) a -> Vector n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n m a. (KnownNat n, KnownNat m) => Vector (n + m) a -> Vector m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. (KnownNat n, KnownNat m) => p n -> Vector (n + m) a -> Vector m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m a. (KnownNat n, KnownNat m) => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a p. (KnownNat n, KnownNat m) => p n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. a -> Vector 1 a -- | O(n) Construct a vector in a type safe manner fromTuple (1,2) -- :: Vector 2 Int fromTuple ("hey", "what's", "going", "on") :: Vector 4 -- String fromTuple :: forall input length ty. (IndexedListLiterals input length ty, KnownNat length) => input -> Vector length ty -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall n a. KnownNat n => a -> Vector n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall n a p. KnownNat n => p n -> a -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall n a. KnownNat n => (Finite n -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall n a p. KnownNat n => p n -> (Finite n -> a) -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall n a. KnownNat n => (a -> a) -> a -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall n a p. KnownNat n => p n -> (a -> a) -> a -> Vector n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall n m a. (KnownNat n, Monad m) => m a -> m (Vector n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall n m a p. (KnownNat n, Monad m) => p n -> m a -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall n m a. (KnownNat n, Monad m) => (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall n m a p. (KnownNat n, Monad m) => p n -> (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall n a b. KnownNat n => (b -> (a, b)) -> b -> Vector n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall n a b p. KnownNat n => p n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall n a. (KnownNat n, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall n a p. (KnownNat n, Num a) => a -> p n -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall n a p. (KnownNat n, Num a) => a -> a -> p n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. a -> Vector n a -> Vector (1 + n) a -- | O(n) Append an element. snoc :: forall n a. Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Vector n a -> Vector m a -> Vector (n + m) a -- | O(n) Yield the argument but force it not to retain any extra -- memory, possibly by copying it. -- -- This is especially useful when dealing with slices. For example: -- --
-- force (slice 0 2 <huge vector>) ---- -- Here, the slice retains a reference to the huge vector. Forcing it -- creates a copy of just the elements that belong to the slice and -- allows the huge vector to be garbage collected. force :: Vector n a -> Vector n a -- | O(m+n) For each pair (i,a) from the list, replace the -- vector element at position i by a. -- --
-- <5,9,2,7> // [(2,1),(0,3),(2,8)] = <3,9,8,7> --(//) :: Vector m a -> [(Finite m, a)] -> Vector m a -- | O(m+n) For each pair (i,a) from the vector of -- index/value pairs, replace the vector element at position i -- by a. -- --
-- update <5,9,2,7> <(2,1),(0,3),(2,8)> = <3,9,8,7> --update :: Vector m a -> Vector n (Int, a) -> Vector m a -- | O(m+n) For each index i from the index vector and the -- corresponding value a from the value vector, replace the -- element of the initial vector at position i by a. -- --
-- update_ <5,9,2,7> <2,0,2> <1,3,8> = <3,9,8,7> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: Vector m a -> [(Int, a)] -> Vector m a -- | Same as update but without bounds checking. unsafeUpdate :: Vector m a -> Vector n (Int, a) -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | O(m+n) For each pair (i,b) from the list, replace the -- vector element a at position i by f a b. -- --
-- accum (+) <5,9,2> [(2,4),(1,6),(0,3),(1,7)] = <5+3, 9+6+7, 2+4> --accum :: (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | O(m+n) For each pair (i,b) from the vector of pairs, -- replace the vector element a at position i by f -- a b. -- --
-- accumulate (+) <5,9,2> <(2,4),(1,6),(0,3),(1,7)> = <5+3, 9+6+7, 2+4> --accumulate :: (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | O(m+n) For each index i from the index vector and the -- corresponding value b from the the value vector, replace the -- element of the initial vector at position i by f a -- b. -- --
-- accumulate_ (+) <5,9,2> <2,1,0,1> <4,6,3,7> = <5+3, 9+6+7, 2+4> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector reverse :: Vector n a -> Vector n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Vector m a -> Vector n Int -> Vector n a -- | Lens to access (O(1)) and update (O(n)) an arbitrary -- element by its index. ix :: forall n a f. (KnownNat n, Functor f) => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a) -- | Lens to access (O(1)) and update (O(n)) the first -- element of a non-empty vector. _head :: forall n a f. (KnownNat n, Functor f) => (a -> f a) -> Vector (1 + n) a -> f (Vector (1 + n) a) -- | Lens to access (O(1)) and update (O(n)) the last element -- of a non-empty vector. _last :: forall n a f. (KnownNat n, Functor f) => (a -> f a) -> Vector (n + 1) a -> f (Vector (n + 1) a) -- | O(n) Pair each element in a vector with its index indexed :: Vector n a -> Vector n (Finite n, a) -- | O(n) Map a function over a vector map :: (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Finite n -> a -> b) -> Vector n a -> Vector n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (a -> Vector m b) -> Vector n a -> Vector (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: Monad m => (a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: Monad m => (Finite n -> a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: Monad m => (a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: Monad m => (Finite n -> a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results. Equvalent to flip mapM. forM :: Monad m => Vector n a -> (a -> m b) -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: Monad m => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Finite n -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Finite n -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Finite n -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Finite n -> a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f izipWith6 :: (Finite n -> a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length zip :: Vector n a -> Vector n b -> Vector n (a, b) zip3 :: Vector n a -> Vector n b -> Vector n c -> Vector n (a, b, c) zip4 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n (a, b, c, d) zip5 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n (a, b, c, d, e) zip6 :: Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: Monad m => (a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: Monad m => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: Monad m => (a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: Monad m => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: Vector n (a, b) -> (Vector n a, Vector n b) unzip3 :: Vector n (a, b, c) -> (Vector n a, Vector n b, Vector n c) unzip4 :: Vector n (a, b, c, d) -> (Vector n a, Vector n b, Vector n c, Vector n d) unzip5 :: Vector n (a, b, c, d, e) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e) unzip6 :: Vector n (a, b, c, d, e, f) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e, Vector n f) -- | O(n) Check if the vector contains an element elem :: Eq a => a -> Vector n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: Eq a => a -> Vector n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: (a -> Bool) -> Vector n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: (a -> Bool) -> Vector n a -> Maybe (Finite n) -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Eq a) => a -> Vector n a -> Maybe (Finite n) -- | O(n) Left fold foldl :: (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: KnownNat n => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Left fold with strict accumulator foldl' :: (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: KnownNat n => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Right fold foldr :: (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if all elements are True and :: Vector n Bool -> Bool -- | O(n) Check if any element is True or :: Vector n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Num a) => Vector n a -> a -- | O(n) Compute the produce of the elements product :: (Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Ord a, KnownNat n) => Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Ord a, KnownNat n) => Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: KnownNat n => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Monadic fold foldM :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (1 + n) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: Monad m => Vector n (m a) -> m (Vector n a) -- | Evaluate each action and discard the results sequence_ :: Monad m => Vector n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator prescanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan postscanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator postscanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan scanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan over a non-empty vector scanl1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan postscanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan scanr :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: KnownNat n => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Convert a vector to a list toList :: Vector n a -> [a] -- | O(n) Convert a list to a vector fromList :: KnownNat n => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall n a. KnownNat n => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a p. KnownNat n => p n -> [a] -> Maybe (Vector n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall a r. [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | O(n) Yield an immutable copy of the mutable vector. freeze :: PrimMonad m => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: PrimMonad m => Vector n a -> m (MVector n (PrimState m) a) -- | O(n) Copy an immutable vector into a mutable one. copy :: PrimMonad m => MVector n (PrimState m) a -> Vector n a -> m () -- | O(1) Unsafely convert a mutable vector to an immutable one -- withouy copying. The mutable vector may not be used after this -- operation. unsafeFreeze :: PrimMonad m => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Unsafely convert an immutable vector to a mutable one -- without copying. The immutable vector may not be used after this -- operation. unsafeThaw :: PrimMonad m => Vector n a -> m (MVector n (PrimState m) a) -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall n a. KnownNat n => Vector a -> Maybe (Vector n a) -- | Takes a Vector and returns a continuation providing a -- Vector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall a r. Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r fromSized :: Vector n a -> Vector a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: (Vector a -> Vector b) -> Vector n a -> Vector n b -- | This module re-exports the functionality in Sized specialized -- to Mutable -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Storable.Mutable.Sized -- | Vector specialized to use Mutable type MVector = MVector MVector -- | O(1) Yield the length of the mutable vector as an Int. length :: forall n s a. (KnownNat n) => MVector n s a -> Int -- | O(1) Yield the length of the mutable vector as a Proxy. length' :: forall n s a. (KnownNat n) => MVector n s a -> Proxy n -- | O(1) Check whether the mutable vector is empty null :: forall n s a. (KnownNat n) => MVector n s a -> Bool -- | O(1) Yield a slice of the mutable vector without copying it -- with an inferred length argument. slice :: forall i n k s a p. (KnownNat i, KnownNat n, KnownNat k, Storable a) => p i -> MVector ((i + n) + k) s a -> MVector n s a -- | O(1) Yield a slice of the mutable vector without copying it -- with an explicit length argument. slice' :: forall i n k s a p. (KnownNat i, KnownNat n, KnownNat k, Storable a) => p i -> p n -> MVector ((i + n) + k) s a -> MVector n s a -- | O(1) Yield all but the last element of a non-empty mutable -- vector without copying. init :: forall n s a. Storable a => MVector (n + 1) s a -> MVector n s a -- | O(1) Yield all but the first element of a non-empty mutable -- vector without copying. tail :: forall n s a. Storable a => MVector (1 + n) s a -> MVector n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n k s a. (KnownNat n, KnownNat k, Storable a) => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n k s a p. (KnownNat n, KnownNat k, Storable a) => p n -> MVector (n + k) s a -> MVector n s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n k s a. (KnownNat n, KnownNat k, Storable a) => MVector (n + k) s a -> MVector k s a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n k s a p. (KnownNat n, KnownNat k, Storable a) => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m s a. (KnownNat n, KnownNat m, Storable a) => MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. (KnownNat n, KnownNat m, Storable a) => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. overlaps :: forall n k s a. (KnownNat n, KnownNat k, Storable a) => MVector n s a -> MVector k s a -> Bool -- | Create a mutable vector where the length is inferred from the type. new :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type. -- The memory is not initialized. unsafeNew :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with an initial value. replicate :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with an initial value. replicate' :: forall n m a p. (KnownNat n, PrimMonad m, Storable a) => p n -> a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is inferred from the type and -- fill it with values produced by repeatedly executing the monadic -- action. replicateM :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => m a -> m (MVector n (PrimState m) a) -- | Create a mutable vector where the length is given explicitly as a -- Proxy argument and fill it with values produced by repeatedly -- executing the monadic action. replicateM' :: forall n m a p. (KnownNat n, PrimMonad m, Storable a) => p n -> m a -> m (MVector n (PrimState m) a) -- | Create a copy of a mutable vector. clone :: forall n m a. (PrimMonad m, Storable a) => MVector n (PrimState m) a -> m (MVector n (PrimState m) a) -- | Grow a mutable vector by an amount given explicitly as a Proxy -- argument. grow :: forall n k m a p. (KnownNat k, PrimMonad m, Storable a) => p k -> MVector n (PrimState m) a -> m (MVector (n + k) (PrimState m) a) -- | Grow a mutable vector (from the front) by an amount given explicitly -- as a Proxy argument. growFront :: forall n k m a p. (KnownNat k, PrimMonad m, Storable a) => p k -> MVector n (PrimState m) a -> m (MVector (n + k) (PrimState m) a) -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. clear :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> m () -- | O(1) Yield the element at a given type-safe position using -- Finite. read :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Finite n -> m a -- | O(1) Yield the element at a given type-safe position using -- Proxy. read' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m, Storable a) => MVector ((n + k) + 1) (PrimState m) a -> p k -> m a -- | O(1) Replace the element at a given type-safe position using -- Finite. write :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Finite n -> a -> m () -- | O(1) Replace the element at a given type-safe position using -- Proxy. write' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m, Storable a) => MVector ((n + k) + 1) (PrimState m) a -> p k -> a -> m () -- | O(1) Modify the element at a given type-safe position using -- Finite. modify :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> (a -> a) -> Finite n -> m () -- | O(1) Modify the element at a given type-safe position using -- Proxy. modify' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m, Storable a) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at a given type-safe position using -- Finites. swap :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Finite n -> Finite n -> m () -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Finite n -> a -> m a -- | O(1) Replace the element at a given type-safe position and -- return the old element, using Finite. exchange' :: forall n k a m p. (KnownNat n, KnownNat k, PrimMonad m, Storable a) => MVector ((n + k) + 1) (PrimState m) a -> p k -> a -> m a -- | O(1) Yield the element at a given Int position without -- bounds checking. unsafeRead :: forall n a m. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Int -> m a -- | O(1) Replace the element at a given Int position without -- bounds checking. unsafeWrite :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Int -> a -> m () -- | O(1) Modify the element at a given Int position without -- bounds checking. unsafeModify :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at a given Int position without -- bounds checking. unsafeSwap :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Int -> Int -> m () -- | O(1) Replace the element at a given Int position and -- return the old element. No bounds checks are performed. unsafeExchange :: forall n m a. (KnownNat n, PrimMonad m, Storable a) => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next (lexicographically) permutation of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (KnownNat n, Ord e, PrimMonad m, Storable e) => MVector n (PrimState m) e -> m Bool -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors may not overlap. copy :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Move the contents of a vector. If the two vectors do not overlap, this -- is equivalent to copy. Otherwise, the copying is performed as -- if the source vector were copied to a temporary vector and then the -- temporary vector was copied to the target vector. move :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Copy a vector. The two vectors may not overlap. This is not checked. unsafeCopy :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> MVector n (PrimState m) a -> m () -- | Convert a MVector into a MVector if it has the correct -- size, otherwise return Nothing. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. toSized :: forall n a s. (KnownNat n, Storable a) => MVector s a -> Maybe (MVector n s a) -- | Takes a MVector and returns a continuation providing a -- MVector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a MVector into a MVector with the -- correct size parameter n. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. withSized :: forall s a r. Storable a => MVector s a -> (forall n. KnownNat n => MVector n s a -> r) -> r -- | Convert a MVector into a MVector. -- -- Note that this does no copying; the returned MVector is a -- reference to the exact same vector in memory as the given one, and any -- modifications to it are also reflected in the given MVector. fromSized :: MVector n s a -> MVector s a -- | This module re-exports the functionality in Sized specialized -- to Storable -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resultant vector size is not know until compile -- time are not exported. module Data.Vector.Storable.Sized -- | Vector specialized to use Storable type Vector = Vector Vector -- | Vector specialized to use Mutable type MVector = MVector MVector -- | O(1) Yield the length of the vector as an Int. This is -- more like natVal than length, extracting the value from -- the KnownNat instance and not looking at the vector itself. length :: forall n a. KnownNat n => Vector n a -> Int -- | O(1) Yield the length of the vector as a Proxy. This -- function doesn't do anything; it merely allows the size -- parameter of the vector to be passed around as a Proxy. length' :: forall n a. Vector n a -> Proxy n -- | O(1) Reveal a KnownNat instance for a vector's length, -- determined at runtime. knownLength :: forall n a r. Storable a => Vector n a -> (KnownNat n => r) -> r -- | O(1) Reveal a KnownNat instance and Proxy for a -- vector's length, determined at runtime. knownLength' :: forall n a r. Storable a => Vector n a -> (KnownNat n => Proxy n -> r) -> r -- | O(1) Safe indexing using a Finite. index :: forall n a. (KnownNat n, Storable a) => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. (KnownNat n, KnownNat m, Storable a) => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. (KnownNat n, Storable a) => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. (Storable a) => Vector (1 + n) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. (Storable a) => Vector (n + 1) a -> a -- | O(1) Safe indexing in a monad. See the documentation for -- indexM for an explanation of why this is useful. indexM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector n a -> Finite n -> m a -- | O(1) Safe indexing in a monad using a Proxy. See the -- documentation for indexM for an explanation of why this is -- useful. indexM' :: forall n k a m p. (KnownNat n, KnownNat k, Storable a, Monad m) => Vector (n + k) a -> p n -> m a -- | O(1) Indexing using an Int without bounds checking. See the -- documentation for indexM for an explanation of why this is -- useful. unsafeIndexM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector n a -> Int -> m a -- | O(1) Yield the first element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. headM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector (1 + n) a -> m a -- | O(1) Yield the last element of a non-empty vector in a monad. -- See the documentation for indexM for an explanation of why this -- is useful. lastM :: forall n a m. (KnownNat n, Storable a, Monad m) => Vector (n + 1) a -> m a -- | O(1) Yield a slice of the vector without copying it with an -- inferred length argument. slice :: forall i n m a p. (KnownNat i, KnownNat n, KnownNat m, Storable a) => p i -> Vector ((i + n) + m) a -> Vector n a -- | O(1) Yield a slice of the vector without copying it with an -- explicit length argument. slice' :: forall i n m a p. (KnownNat i, KnownNat n, KnownNat m, Storable a) => p i -> p n -> Vector ((i + n) + m) a -> Vector n a -- | O(1) Yield all but the last element of a non-empty vector -- without copying. init :: forall n a. (Storable a) => Vector (n + 1) a -> Vector n a -- | O(1) Yield all but the first element of a non-empty vector -- without copying. tail :: forall n a. (Storable a) => Vector (1 + n) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- inferred from the type. take :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resultant vector always -- contains this many elements. The length of the resultant vector is -- given explicitly as a Proxy argument. take' :: forall n m a p. (KnownNat n, KnownNat m, Storable a) => p n -> Vector (n + m) a -> Vector n a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is inferred from the type. drop :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (n + m) a -> Vector m a -- | O(1) Yield all but the the first n elements. The given vector -- must contain at least this many elements The length of the resultant -- vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. (KnownNat n, KnownNat m, Storable a) => p n -> Vector (n + m) a -> Vector m a -- | O(1) Yield the first n elements paired with the remainder -- without copying. The lengths of the resultant vector are inferred from -- the type. splitAt :: forall n m a. (KnownNat n, KnownNat m, Storable a) => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements paired with the remainder -- without copying. The length of the first resultant vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a p. (KnownNat n, KnownNat m, Storable a) => p n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. (Storable a) => Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. (Storable a) => a -> Vector 1 a -- | O(n) Construct a vector in a type safe manner fromTuple (1,2) -- :: Vector 2 Int fromTuple ("hey", "what's", "going", "on") :: Vector 4 -- String fromTuple :: forall a input length. (Storable a, IndexedListLiterals input length a, KnownNat length) => input -> Vector length a -- | O(n) Construct a vector with the same element in each position -- where the length is inferred from the type. replicate :: forall n a. (KnownNat n, Storable a) => a -> Vector n a -- | O(n) Construct a vector with the same element in each position -- where the length is given explicitly as a Proxy argument. replicate' :: forall n a p. (KnownNat n, Storable a) => p n -> a -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is inferred from the type. generate :: forall n a. (KnownNat n, Storable a) => (Finite n -> a) -> Vector n a -- | O(n) construct a vector of the given length by applying the -- function to each index where the length is given explicitly as a -- Proxy argument. generate' :: forall n a p. (KnownNat n, Storable a) => p n -> (Finite n -> a) -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is inferred from the type. iterateN :: forall n a. (KnownNat n, Storable a) => (a -> a) -> a -> Vector n a -- | O(n) Apply function n times to value. Zeroth element is -- original value. The length is given explicitly as a Proxy -- argument. iterateN' :: forall n a p. (KnownNat n, Storable a) => p n -> (a -> a) -> a -> Vector n a -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is inferred from the type. replicateM :: forall n m a. (KnownNat n, Storable a, Monad m) => m a -> m (Vector n a) -- | O(n) Execute the monadic action n times and store the -- results in a vector where n is given explicitly as a -- Proxy argument. replicateM' :: forall n m a p. (KnownNat n, Storable a, Monad m) => p n -> m a -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is inferred from the type. generateM :: forall n m a. (KnownNat n, Storable a, Monad m) => (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector of length n by applying the -- monadic action to each index where n is given explicitly as a -- Proxy argument. generateM' :: forall n m a p. (KnownNat n, Storable a, Monad m) => p n -> (Finite n -> m a) -> m (Vector n a) -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is inferred from the type. unfoldrN :: forall n a b. (KnownNat n, Storable a) => (b -> (a, b)) -> b -> Vector n a -- | O(n) Construct a vector with exactly n elements by -- repeatedly applying the generator function to the a seed. The length, -- n, is given explicitly as a Proxy argument. unfoldrN' :: forall n a b p. (KnownNat n, Storable a) => p n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is inferred from -- the type. enumFromN :: forall n a. (KnownNat n, Storable a, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1 etc. The length, n, is given -- explicitly as a Proxy argument. enumFromN' :: forall n a p. (KnownNat n, Storable a, Num a) => a -> p n -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Storable a, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. The length, n, -- is given explicitly as a Proxy argument. enumFromStepN' :: forall n a p. (KnownNat n, Storable a, Num a) => a -> a -> p n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. Storable a => a -> Vector n a -> Vector (1 + n) a -- | O(n) Append an element. snoc :: forall n a. Storable a => Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Storable a => Vector n a -> Vector m a -> Vector (n + m) a -- | O(n) Yield the argument but force it not to retain any extra -- memory, possibly by copying it. -- -- This is especially useful when dealing with slices. For example: -- --
-- force (slice 0 2 <huge vector>) ---- -- Here, the slice retains a reference to the huge vector. Forcing it -- creates a copy of just the elements that belong to the slice and -- allows the huge vector to be garbage collected. force :: Storable a => Vector n a -> Vector n a -- | O(m+n) For each pair (i,a) from the list, replace the -- vector element at position i by a. -- --
-- <5,9,2,7> // [(2,1),(0,3),(2,8)] = <3,9,8,7> --(//) :: (Storable a) => Vector m a -> [(Finite m, a)] -> Vector m a -- | O(m+n) For each pair (i,a) from the vector of -- index/value pairs, replace the vector element at position i -- by a. -- --
-- update <5,9,2,7> <(2,1),(0,3),(2,8)> = <3,9,8,7> --update :: (Storable a, Storable (Int, a)) => Vector m a -> Vector n (Int, a) -> Vector m a -- | O(m+n) For each index i from the index vector and the -- corresponding value a from the value vector, replace the -- element of the initial vector at position i by a. -- --
-- update_ <5,9,2,7> <2,0,2> <1,3,8> = <3,9,8,7> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, update is probably more convenient. -- --
-- update_ xs is ys = update xs (zip is ys) --update_ :: Storable a => Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: (Storable a) => Vector m a -> [(Int, a)] -> Vector m a -- | Same as update but without bounds checking. unsafeUpdate :: (Storable a, Storable (Int, a)) => Vector m a -> Vector n (Int, a) -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Storable a => Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | O(m+n) For each pair (i,b) from the list, replace the -- vector element a at position i by f a b. -- --
-- accum (+) <5,9,2> [(2,4),(1,6),(0,3),(1,7)] = <5+3, 9+6+7, 2+4> --accum :: Storable a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | O(m+n) For each pair (i,b) from the vector of pairs, -- replace the vector element a at position i by f -- a b. -- --
-- accumulate (+) <5,9,2> <(2,4),(1,6),(0,3),(1,7)> = <5+3, 9+6+7, 2+4> --accumulate :: (Storable a, Storable (Int, b)) => (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | O(m+n) For each index i from the index vector and the -- corresponding value b from the the value vector, replace the -- element of the initial vector at position i by f a -- b. -- --
-- accumulate_ (+) <5,9,2> <2,1,0,1> <4,6,3,7> = <5+3, 9+6+7, 2+4> ---- -- This function is useful for instances of Vector that cannot -- store pairs. Otherwise, accumulate is probably more convenient: -- --
-- accumulate_ f as is bs = accumulate f as (zip is bs) --accumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: Storable a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (Storable a, Storable (Int, b)) => (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector reverse :: (Storable a) => Vector n a -> Vector n a -- | O(n) Yield the vector obtained by replacing each element -- i of the index vector by xs!i. This is -- equivalent to map (xs!) is but is often much -- more efficient. -- --
-- backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a> --backpermute :: Storable a => Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Storable a => Vector m a -> Vector n Int -> Vector n a -- | Lens to access (O(1)) and update (O(n)) an arbitrary -- element by its index. ix :: forall n a f. (KnownNat n, Storable a, Functor f) => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a) -- | Lens to access (O(1)) and update (O(n)) the first -- element of a non-empty vector. _head :: forall n a f. (KnownNat n, Storable a, Functor f) => (a -> f a) -> Vector (1 + n) a -> f (Vector (1 + n) a) -- | Lens to access (O(1)) and update (O(n)) the last element -- of a non-empty vector. _last :: forall n a f. (KnownNat n, Storable a, Functor f) => (a -> f a) -> Vector (n + 1) a -> f (Vector (n + 1) a) -- | O(n) Pair each element in a vector with its index indexed :: (Storable a, Storable (Int, a), Storable (Finite n, a)) => Vector n a -> Vector n (Finite n, a) -- | O(n) Map a function over a vector map :: (Storable a, Storable b) => (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index imap :: (Storable a, Storable b) => (Finite n -> a -> b) -> Vector n a -> Vector n b -- | O(n*m) Map a function over a vector and concatenate the -- results. The function is required to always return the same length -- vector. concatMap :: (Storable a, Storable b) => (a -> Vector m b) -> Vector n a -> Vector (n * m) b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: (Monad m, Storable a, Storable b) => (a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to every element of a vector and -- its index, yielding a vector of results imapM :: (Monad m, Storable a, Storable b) => (Finite n -> a -> m b) -> Vector n a -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results mapM_ :: (Monad m, Storable a) => (a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to every element of a vector and -- its index, ignoring the results imapM_ :: (Monad m, Storable a) => (Finite n -> a -> m b) -> Vector n a -> m () -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results. Equvalent to flip mapM. forM :: (Monad m, Storable a, Storable b) => Vector n a -> (a -> m b) -> m (Vector n b) -- | O(n) Apply the monadic action to all elements of a vector and -- ignore the results. Equivalent to flip mapM_. forM_ :: (Monad m, Storable a) => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f zipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => (a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length with a function that -- also takes the elements' indices). izipWith :: (Storable a, Storable b, Storable c) => (Finite n -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (Finite n -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e) => (Finite n -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => (Finite n -> a -> b -> c -> d -> e -> f) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f izipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => (Finite n -> a -> b -> c -> d -> e -> f -> g) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n g -- | O(n) Zip two vectors of the same length zip :: (Storable a, Storable b, Storable (a, b)) => Vector n a -> Vector n b -> Vector n (a, b) zip3 :: (Storable a, Storable b, Storable c, Storable (a, b, c)) => Vector n a -> Vector n b -> Vector n c -> Vector n (a, b, c) zip4 :: (Storable a, Storable b, Storable c, Storable d, Storable (a, b, c, d)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n (a, b, c, d) zip5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable (a, b, c, d, e)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n (a, b, c, d, e) zip6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable (a, b, c, d, e, f)) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n f -> Vector n (a, b, c, d, e, f) -- | O(n) Zip the two vectors of the same length with the monadic -- action and yield a vector of results zipWithM :: (Monad m, Storable a, Storable b, Storable c) => (a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and yield a vector of results izipWithM :: (Monad m, Storable a, Storable b, Storable c) => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m (Vector n c) -- | O(n) Zip the two vectors with the monadic action and ignore the -- results zipWithM_ :: (Monad m, Storable a, Storable b) => (a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(n) Zip the two vectors with a monadic action that also takes -- the element index and ignore the results izipWithM_ :: (Monad m, Storable a, Storable b) => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: (Storable a, Storable b, Storable (a, b)) => Vector n (a, b) -> (Vector n a, Vector n b) unzip3 :: (Storable a, Storable b, Storable c, Storable (a, b, c)) => Vector n (a, b, c) -> (Vector n a, Vector n b, Vector n c) unzip4 :: (Storable a, Storable b, Storable c, Storable d, Storable (a, b, c, d)) => Vector n (a, b, c, d) -> (Vector n a, Vector n b, Vector n c, Vector n d) unzip5 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable (a, b, c, d, e)) => Vector n (a, b, c, d, e) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e) unzip6 :: (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable (a, b, c, d, e, f)) => Vector n (a, b, c, d, e, f) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e, Vector n f) -- | O(n) Check if the vector contains an element elem :: (Storable a, Eq a) => a -> Vector n a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: (Storable a, Eq a) => a -> Vector n a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. find :: Storable a => (a -> Bool) -> Vector n a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. findIndex :: Storable a => (a -> Bool) -> Vector n a -> Maybe (Finite n) -- | O(n) Yield Just the index of the first occurence of the -- given element or Nothing if the vector does not contain the -- element. This is a specialised version of findIndex. elemIndex :: (Storable a, Eq a) => a -> Vector n a -> Maybe (Finite n) -- | O(n) Left fold foldl :: Storable b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Left fold with strict accumulator foldl' :: Storable b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Right fold foldr :: Storable a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator foldr' :: Storable a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: Storable b => (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: Storable b => (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: Storable a => (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: Storable a => (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Storable a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Storable a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if all elements are True and :: Vector n Bool -> Bool -- | O(n) Check if any element is True or :: Vector n Bool -> Bool -- | O(n) Compute the sum of the elements sum :: (Storable a, Num a) => Vector n a -> a -- | O(n) Compute the produce of the elements product :: (Storable a, Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the maximum element of the non-empty -- vector according to the given comparison function. maxIndexBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector. minIndex :: (Storable a, Ord a, KnownNat n) => Vector (n + 1) a -> Finite (n + 1) -- | O(n) Yield the index of the minimum element of the non-empty -- vector according to the given comparison function. minIndexBy :: (Storable a, KnownNat n) => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Monadic fold foldM :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold (action applied to each element and its -- index) ifoldM :: (Monad m, Storable b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (1 + n) a -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold with strict accumulator (action applied to -- each element and its index) ifoldM' :: (Monad m, Storable b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold that discards the result (action applied to -- each element and its index) ifoldM_ :: (Monad m, Storable b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: (Monad m, Storable b) => (a -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result (action applied to each element and its index) ifoldM'_ :: (Monad m, Storable b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m () -- | O(n) Monad fold over non-empty vectors with strict accumulator -- that discards the result fold1M'_ :: (Monad m, Storable a, KnownNat n) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | Evaluate each action and collect the results sequence :: (Monad m, Storable a, Storable (m a)) => Vector n (m a) -> m (Vector n a) -- | Evaluate each action and discard the results sequence_ :: (Monad m, Storable (m a)) => Vector n (m a) -> m () -- | O(n) Prescan -- --
-- prescanl f z = init . scanl f z ---- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan over a non-empty vector scanl1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left prescan prescanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan postscanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan scanr :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (Storable a, Storable b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: (Storable a, KnownNat n) => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 1) a -- | O(n) Convert a vector to a list toList :: Storable a => Vector n a -> [a] -- | O(n) Convert a list to a vector fromList :: (Storable a, KnownNat n) => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is inferred from the type. fromListN :: forall n a. (Storable a, KnownNat n) => [a] -> Maybe (Vector n a) -- | O(n) Convert the first n elements of a list to a -- vector. The length of the resultant vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a p. (Storable a, KnownNat n) => p n -> [a] -> Maybe (Vector n a) -- | O(n) Takes a list and returns a continuation providing a vector -- with a size parameter corresponding to the length of the list. -- -- Essentially converts a list into a vector with the proper size -- parameter, determined at runtime. -- -- See withSized withSizedList :: forall a r. Storable a => [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | O(n) Yield an immutable copy of the mutable vector. freeze :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: (PrimMonad m, Storable a) => Vector n a -> m (MVector n (PrimState m) a) -- | O(n) Copy an immutable vector into a mutable one. copy :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> Vector n a -> m () -- | O(1) Unsafely convert a mutable vector to an immutable one -- withouy copying. The mutable vector may not be used after this -- operation. unsafeFreeze :: (PrimMonad m, Storable a) => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Unsafely convert an immutable vector to a mutable one -- without copying. The immutable vector may not be used after this -- operation. unsafeThaw :: (PrimMonad m, Storable a) => Vector n a -> m (MVector n (PrimState m) a) -- | Convert a Vector into a Vector if it has the correct -- size, otherwise return Nothing. toSized :: forall n a. (Storable a, KnownNat n) => Vector a -> Maybe (Vector n a) -- | Takes a Vector and returns a continuation providing a -- Vector with a size parameter n that is determined at -- runtime based on the length of the input vector. -- -- Essentially converts a Vector into a Vector with the -- correct size parameter n. withSized :: forall a r. Storable a => Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r fromSized :: Vector n a -> Vector a -- | Apply a function on unsized vectors to a sized vector. The function -- must preserve the size of the vector, this is not checked. withVectorUnsafe :: forall a b (n :: Nat). (Storable a, Storable b) => (Vector a -> Vector b) -> Vector n a -> Vector n b