-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Size tagged vectors -- -- Please see README.md @package vector-sized @version 1.5.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 (n :: Nat) 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 (GHC.TypeNats.KnownNat n, Data.Typeable.Internal.Typeable v, Data.Typeable.Internal.Typeable s, Data.Typeable.Internal.Typeable a, Data.Data.Data (v s a)) => Data.Data.Data (Data.Vector.Generic.Mutable.Sized.Internal.MVector v n s a) -- | This module reexports the functionality in Mutable which maps -- well to explicitly 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 known until runtime -- 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. () => 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, 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, 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall v n k s a. (KnownNat n, MVector v a) => MVector v (n + k) s a -> MVector v n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall v n k s a p. (KnownNat n, 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 -- resulting vector is inferred from the type. drop :: forall v n k s a. (KnownNat n, 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 -- resulting vector is given explicitly as a Proxy argument. drop' :: forall v n k s a p. (KnownNat n, 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 rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall v n m s a. (KnownNat n, 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 rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall v n m s a p. (KnownNat n, MVector v a) => p n -> MVector v (n + m) s a -> (MVector v n s a, MVector v m s a) -- | O(1) Check whether two vectors overlap. overlaps :: forall v n k s a. 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. (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 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. (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 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. (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 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 given type-safe positions using -- Finites. swap :: forall v n m a. (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. (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 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. (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. (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. (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at given Int positions without -- bounds checking. unsafeSwap :: forall v n m a. (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. (PrimMonad m, MVector v a) => MVector v n (PrimState m) a -> Int -> a -> m a -- | Compute the next permutation (in lexicographic order) of a given -- vector in-place. Returns False when the input is the last -- permutation. nextPermutation :: forall v n e m. (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 (n :: Nat) a instance (GHC.TypeNats.KnownNat n, Data.Typeable.Internal.Typeable v, Data.Typeable.Internal.Typeable a, Data.Data.Data (v a)) => 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 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) instance (GHC.Ix.Ix a, GHC.Classes.Ord (v a), Data.Vector.Generic.Base.Vector v a) => GHC.Ix.Ix (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 -- | Pattern synonym that lets you treat an unsized vector as if it -- "contained" a sized vector. If you pattern match on an unsized vector, -- its contents will be the sized vector counterpart. -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc (SomeSized v) =
--       sum (zipWith (+) v (replicate 1))
--           -- ^ here, v is `Sized.Vector n Int`, and we have
--                       `KnownNat n`
--   
-- -- The n type variable will be properly instantiated to whatever -- the length of the vector is, and you will also have a -- KnownNat n instance available. You can get n -- in scope by turning on ScopedTypeVariables and matching on -- SomeSized (v :: Sized.Vector n Int). -- -- Without this, you would otherwise have to use withSized to do -- the same thing: -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc u = withSized u $ \v ->
--       sum (zipWith (+) v (replicate 1))
--   
-- -- Remember that the type of final result of your function (the -- Int, here) must not depend on n. However, the -- types of the intermediate values are allowed to depend on n. -- -- This is especially useful in do blocks, where you can pattern -- match on the unsized results of actions, to use the sized vector in -- the rest of the do block. You also get a KnownNat n -- constraint for the remainder of the do block. -- --
--   -- If you had:
--   getAVector :: IO (Unsized.Vector Int)
--   
--   main :: IO ()
--   main = do
--       SomeSized v <- getAVector -- v is `Sized.Vector n Int`
--       print v
--   
--       -- alternatively, get n in scope
--       SomeSized (v2 :: Sized.Vector n Int) <- getAVector
--       print v2
--   
-- -- Remember that the final type of the result of the do block -- ((), here) must not depend on n. However, the -- -- Also useful in ghci, where you can pattern match to get sized vectors -- from unsized vectors. -- --
--   ghci> SomeSized v <- pure (myUnsizedVector :: Unsized.Vector Int)
--                -- ^ v is `Sized.Vector n Int`
--   
-- -- This enables interactive exploration with sized vectors in ghci, and -- is useful for using with other libraries and functions that expect -- sized vectors in an interactive setting. -- -- (Note that as of GHC 8.6, you cannot get the n in scope in -- your ghci session using ScopedTypeVariables, like you can with do -- blocks) -- -- You can also use this as a constructor, to take a sized vector and -- "hide" the size, to produce an unsized vector: -- --
--   SomeSized :: Sized.Vector n a -> Unsized.Vector a
--   
-- -- Note that due to quirks in GHC pattern synonym completeness checking, -- you will get incomplete pattern matches if you use this -- polymorphically over different vector types, or you use any vector -- type other than the three supported by this library (normal, storable, -- unboxed). pattern SomeSized :: Vector v a => forall n. KnownNat n => Vector v n a -> v 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. 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, 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. 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. -- -- The monad allows operations to be strict in the vector when necessary. -- Suppose vector copying is implemented like this: -- --
--   copy mv v = ... write mv i (v ! i) ...
--   
-- -- For lazy vectors, v ! i would not be evaluated, which means -- that mv would unnecessarily retain a reference to v -- in each element when written. -- -- With indexM, copying can be implemented like this instead: -- --
--   copy mv v = ... do
--                    x <- indexM v i
--                    write mv i x
--   
-- -- Here, no references to v are retained, because indexing (but -- not the elements) are evaluated eagerly. indexM :: forall v n a m. (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, 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. (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. (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. (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, 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, 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall v n m a. (KnownNat n, Vector v a) => Vector v (n + m) a -> Vector v n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall v n m a p. (KnownNat n, 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 -- resulting vector is inferred from the type. drop :: forall v n m a. (KnownNat n, 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall v n m a p. (KnownNat n, Vector v a) => p n -> Vector v (n + m) a -> Vector v m a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall v n m a. (KnownNat n, 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 rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall v n m a p. (KnownNat n, 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 the function n times to a value. Zeroth -- element is the 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 the function n times to a value. Zeroth -- element is the 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 -- 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 -- 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, ... x + (n - 1). The length 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, ..., x + (n - 1) The length 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+2y, ... x + (n - 1)y. -- The length 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+2y, ..., x + (n - 1)y. -- The length 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 -> [(Finite m, 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. (Vector v a, Functor f) => Finite n -> (a -> f a) -> Vector v n a -> f (Vector v n a) -- | Type-safe lens to access (O(1)) and update (O(n)) an -- arbitrary element by its index which should be supplied via -- TypeApplications. ix' :: forall i v n a f. (Vector v a, Functor f, KnownNat i, KnownNat n, (i + 1) <= 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. (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. (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 a vector of the -- same length. 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 => (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 => (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 => (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 => (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 product 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) => 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 => (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) => 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 => (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) => 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 => (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) => 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 => (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) => (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) => (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) => (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) => (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 (1 + 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 (1 + n) a -- | O(n) Scan over a non-empty vector. scanl1 :: Vector v a => (a -> a -> a) -> Vector v (1 + n) a -> Vector v (2 + n) a -- | O(n) Scan over a non-empty vector with a strict accumulator. scanl1' :: Vector v a => (a -> a -> a) -> Vector v (1 + n) a -> Vector v (2 + n) 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 + 1) 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 + 1) b -- | O(n) Right-to-left scan over a non-empty vector. scanr1 :: Vector v a => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 2) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator. scanr1' :: Vector v a => (a -> a -> a) -> Vector v (n + 1) a -> Vector v (n + 2) 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 :: (v a -> w b) -> Vector v n a -> Vector w n b -- | Apply a function on two unsized vectors to sized vectors. The function -- must preserve the size of the vectors, this is not checked. zipVectorsUnsafe :: (u a -> v b -> w c) -> Vector u n a -> Vector v n b -> Vector w n c 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 GHC.TypeNats.KnownNat n => GHC.Base.Monad (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance (GHC.TypeNats.KnownNat n, n GHC.Types.~ (1 GHC.TypeNats.+ m)) => Control.Comonad.Comonad (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance (GHC.TypeNats.KnownNat n, n GHC.Types.~ (1 GHC.TypeNats.+ m)) => Control.Comonad.ComonadApply (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance (GHC.Base.Semigroup g, Data.Vector.Generic.Base.Vector v g) => GHC.Base.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 GHC.TypeNats.KnownNat n => Data.Distributive.Distributive (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance GHC.TypeNats.KnownNat n => Data.Functor.Rep.Representable (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n) instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a) => Data.Hashable.Class.Hashable (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Vector n a) instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a, Foreign.Storable.Storable a) => Data.Hashable.Class.Hashable (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Storable.Vector n a) instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a, Data.Vector.Unboxed.Base.Unbox a) => Data.Hashable.Class.Hashable (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Unboxed.Base.Vector n a) 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) instance (Data.Vector.Generic.Base.Vector v a, Data.Binary.Class.Binary a, GHC.TypeNats.KnownNat n) => Data.Binary.Class.Binary (Data.Vector.Generic.Sized.Internal.Vector v n a) instance (Data.Vector.Generic.Base.Vector v a, Data.Bits.Bits (v a), Data.Bits.Bits a, GHC.TypeNats.KnownNat n) => Data.Bits.Bits (Data.Vector.Generic.Sized.Internal.Vector v n a) instance (Data.Vector.Generic.Base.Vector v a, Data.Bits.Bits (v a), Data.Bits.FiniteBits a, GHC.TypeNats.KnownNat n) => Data.Bits.FiniteBits (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 resulting vector size is not known until runtime -- 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. () => 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) => 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) => 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n k s a. KnownNat n => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n k s a p. KnownNat n => 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 -- resulting vector is inferred from the type. drop :: forall n k s a. KnownNat n => 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 -- resulting vector is given explicitly as a Proxy argument. drop' :: forall n k s a p. KnownNat n => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m s a. KnownNat n => MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. KnownNat n => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Check if two vectors overlap. overlaps :: forall n k s 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) => 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. 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 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. 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 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. 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 k, PrimMonad m) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at the given type-safe positions using -- Finites. swap :: forall n m a. 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. 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 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. 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. 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. PrimMonad m => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at the given Int positions -- without bounds checking. unsafeSwap :: forall n m a. 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. PrimMonad m => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next permutation (lexicographically) of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (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 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 resulting vector size is not known until runtime -- are not exported. module Data.Vector.Primitive.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. () => 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, Prim 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, Prim 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. Prim 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. Prim a => MVector (1 + n) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n k s a. (KnownNat n, Prim a) => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n k s a p. (KnownNat n, Prim 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 -- resulting vector is inferred from the type. drop :: forall n k s a. (KnownNat n, Prim 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n k s a p. (KnownNat n, Prim a) => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m s a. (KnownNat n, Prim a) => MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. (KnownNat n, Prim a) => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Check if two vectors overlap. overlaps :: forall n k s a. Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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. (PrimMonad m, Prim 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 k, PrimMonad m, Prim 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. (PrimMonad m, Prim 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 k, PrimMonad m, Prim 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. (PrimMonad m, Prim 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 k, PrimMonad m, Prim a) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at the given type-safe positions using -- Finites. swap :: forall n m a. (PrimMonad m, Prim 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. (PrimMonad m, Prim 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 k, PrimMonad m, Prim 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. (PrimMonad m, Prim 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. (PrimMonad m, Prim 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. (PrimMonad m, Prim a) => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at the given Int positions -- without bounds checking. unsafeSwap :: forall n m a. (PrimMonad m, Prim 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. (PrimMonad m, Prim a) => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next permutation (lexicographically) of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (Ord e, PrimMonad m, Prim e) => MVector n (PrimState m) e -> m Bool -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Prim a) => MVector n (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors may not overlap. copy :: (PrimMonad m, Prim 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, Prim 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, Prim 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, Prim 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. Prim 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 Primitive. -- -- 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 resulting vector size is not known until runtime -- are not exported. module Data.Vector.Primitive.Sized -- | Vector specialized to use Primitive. type Vector = Vector Vector -- | Pattern synonym that lets you treat an unsized vector as if it -- "contained" a sized vector. If you pattern match on an unsized vector, -- its contents will be the sized vector counterpart. -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc (SomeSized v) =
--       sum (zipWith (+) v (replicate 1))
--           -- ^ here, v is `Sized.Vector n Int`, and we have
--                       `KnownNat n`
--   
-- -- The n type variable will be properly instantiated to whatever -- the length of the vector is, and you will also have a -- KnownNat n instance available. You can get n -- in scope by turning on ScopedTypeVariables and matching on -- SomeSized (v :: Sized.Vector n Int). -- -- Without this, you would otherwise have to use withSized to do -- the same thing: -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc u = withSized u $ \v ->
--       sum (zipWith (+) v (replicate 1))
--   
-- -- Remember that the type of final result of your function (the -- Int, here) must not depend on n. However, the -- types of the intermediate values are allowed to depend on n. -- -- This is especially useful in do blocks, where you can pattern -- match on the unsized results of actions, to use the sized vector in -- the rest of the do block. You also get a KnownNat n -- constraint for the remainder of the do block. -- --
--   -- If you had:
--   getAVector :: IO (Unsized.Vector Int)
--   
--   main :: IO ()
--   main = do
--       SomeSized v <- getAVector -- v is `Sized.Vector n Int`
--       -- get n in scope
--       SomeSized (v :: Sized.Vector n Int) <- getAVector
--       print v
--   
-- -- Remember that the final type of the result of the do block -- ((), here) must not depend on n. However, the -- -- Also useful in ghci, where you can pattern match to get sized vectors -- from unsized vectors. -- --
--   ghci> SomeSized v <- pure (myUnsizedVector :: Unsized.Vector Int)
--                -- ^ v is `Sized.Vector n Int`
--   
-- -- This enables interactive exploration with sized vectors in ghci, and -- is useful for using with other libraries and functions that expect -- sized vectors in an interactive setting. -- -- (Note that as of GHC 8.6, you cannot get the n in scope in -- your ghci session using ScopedTypeVariables, like you can with do -- blocks) -- -- You can also use this as a constructor, to take a sized vector and -- "hide" the size, to produce an unsized vector: -- --
--   SomeSized :: Sized.Vector n a -> Unsized.Vector a
--   
pattern SomeSized :: Prim a => KnownNat n => Vector n a -> Vector a -- | 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. Prim 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. Prim a => Vector n a -> (KnownNat n => Proxy n -> r) -> r -- | O(1) Safe indexing using a Finite. index :: forall n a. Prim a => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. (KnownNat n, Prim a) => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. Prim a => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. Prim a => Vector (1 + n) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. Prim 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. (Prim 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, Prim 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. (Prim 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. (Prim 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. (Prim 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, Prim 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, Prim 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. Prim 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. Prim a => Vector (1 + n) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n m a. (KnownNat n, Prim a) => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n m a p. (KnownNat n, Prim 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 -- resulting vector is inferred from the type. drop :: forall n m a. (KnownNat n, Prim 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. (KnownNat n, Prim a) => p n -> Vector (n + m) a -> Vector m a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m a. (KnownNat n, Prim 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 resulting vector is -- passed explicitly as a Proxy argument. splitAt' :: forall n m a p. (KnownNat n, Prim a) => p n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. Prim a => Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. Prim 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. (Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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, Prim 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 -- is inferred from the type. unfoldrN :: forall n a b. (KnownNat n, Prim 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 -- is given explicitly as a Proxy argument. unfoldrN' :: forall n a b p. (KnownNat n, Prim a) => p n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1, ..., x + (n - 1). The length is -- inferred from the type. enumFromN :: forall n a. (KnownNat n, Prim a, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1, ..., x + (n - 1). The length is -- given explicitly as a Proxy argument. enumFromN' :: forall n a p. (KnownNat n, Prim 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+2y, ..., x + (n - 1)y. -- The length is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Prim a, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+2y, ..., x + (n - 1)y. -- The length is given explicitly as a Proxy argument. enumFromStepN' :: forall n a p. (KnownNat n, Prim a, Num a) => a -> a -> p n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. Prim a => a -> Vector n a -> Vector (1 + n) a -- | O(n) Append an element. snoc :: forall n a. Prim a => Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Prim 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 :: Prim 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>
--   
(//) :: Prim a => Vector m a -> [(Finite m, 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_ :: Prim a => Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: Prim a => Vector m a -> [(Int, a)] -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Prim 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 :: Prim a => (a -> b -> a) -> Vector m a -> [(Finite m, 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_ :: (Prim a, Prim b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: Prim a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Prim a, Prim b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector. reverse :: Prim 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 :: Prim a => Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Prim 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. (Prim 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. (Prim 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. (Prim a, Functor f) => (a -> f a) -> Vector (n + 1) a -> f (Vector (n + 1) a) -- | O(n) Map a function over a vector. map :: (Prim a, Prim b) => (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index. imap :: (Prim a, Prim 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 :: (Prim a, Prim 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, Prim a, Prim 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, Prim a, Prim 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, Prim 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, Prim 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, Prim a, Prim 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, Prim a) => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Prim a, Prim b, Prim c) => (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (Prim a, Prim b, Prim c, Prim d) => (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e) => (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim 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 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim 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 :: (Prim a, Prim b, Prim c) => (Finite n -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Prim a, Prim b, Prim c, Prim d) => (Finite n -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e) => (Finite n -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim 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 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim 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 the two vectors of the same length with the monadic -- action and yield a vector of results. zipWithM :: (Monad m, Prim a, Prim b, Prim 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, Prim a, Prim b, Prim 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, Prim a, Prim 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, Prim a, Prim b) => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(n) Check if the vector contains an element. elem :: (Prim 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 :: (Prim 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 :: Prim 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 :: Prim 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 :: (Prim a, Eq a) => a -> Vector n a -> Maybe (Finite n) -- | O(n) Left fold. foldl :: Prim b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors. foldl1 :: Prim a => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Left fold with strict accumulator. foldl' :: Prim b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator. foldl1' :: Prim a => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Right fold. foldr :: Prim a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors. foldr1 :: Prim a => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator. foldr' :: Prim a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator. foldr1' :: Prim a => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its -- index). ifoldl :: Prim 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' :: Prim b => (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index). ifoldr :: Prim 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' :: Prim a => (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Prim a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Prim a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Compute the sum of the elements. sum :: (Prim a, Num a) => Vector n a -> a -- | O(n) Compute the product of the elements. product :: (Prim a, Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Prim a, Ord a) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: Prim a => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Prim a, Ord a) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: Prim a => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Prim a, Ord a) => 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 :: Prim a => (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 :: (Prim a, Ord a) => 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 :: Prim a => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Monadic fold. foldM :: (Monad m, Prim 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, Prim b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors. fold1M :: (Monad m, Prim a) => (a -> a -> m a) -> Vector (1 + n) a -> m a -- | O(n) Monadic fold with strict accumulator. foldM' :: (Monad m, Prim 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, Prim 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, Prim a) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result. foldM_ :: (Monad m, Prim 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, Prim 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, Prim a) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result. foldM'_ :: (Monad m, Prim 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, Prim 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, Prim a) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Prescan. -- --
--   prescanl f z = init . scanl f z
--   
-- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator. prescanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan. postscanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator. postscanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan. scanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Haskell-style scan with strict accumulator. scanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Scan over a non-empty vector. scanl1 :: Prim a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Scan over a non-empty vector with a strict accumulator. scanl1' :: Prim a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Right-to-left prescan. prescanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator. prescanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan. postscanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator. postscanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan. scanr :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b -- | O(n) Right-to-left Haskell-style scan with strict accumulator. scanr' :: (Prim a, Prim b) => (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b -- | O(n) Right-to-left scan over a non-empty vector. scanr1 :: Prim a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator. scanr1' :: Prim a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Convert a vector to a list. toList :: Prim a => Vector n a -> [a] -- | O(n) Convert a list to a vector. fromList :: (Prim 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 resulting vector is inferred from the type. fromListN :: forall n a. (Prim 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 resulting vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a p. (Prim 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. Prim a => [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | O(n) Yield an immutable copy of the mutable vector. freeze :: (PrimMonad m, Prim a) => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: (PrimMonad m, Prim a) => Vector n a -> m (MVector n (PrimState m) a) -- | O(n) Copy an immutable vector into a mutable one. copy :: (PrimMonad m, Prim 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, Prim 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, Prim 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. (Prim 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. Prim 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). () => (Vector a -> Vector b) -> Vector n a -> Vector n b -- | This module re-exports the functionality in Sized specialized -- to Vector. -- -- Functions returning a vector determine the size from the type context -- unless they have a ' suffix in which case they take an -- explicit Proxy argument. -- -- Functions where the resulting vector size is not known until runtime -- are not exported. module Data.Vector.Sized -- | Vector specialized to use Vector. type Vector = Vector Vector -- | Pattern synonym that lets you treat an unsized vector as if it -- "contained" a sized vector. If you pattern match on an unsized vector, -- its contents will be the sized vector counterpart. -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc (SomeSized v) =
--       sum (zipWith (+) v (replicate 1))
--           -- ^ here, v is `Sized.Vector n Int`, and we have
--                       `KnownNat n`
--   
-- -- The n type variable will be properly instantiated to whatever -- the length of the vector is, and you will also have a -- KnownNat n instance available. You can get n -- in scope by turning on ScopedTypeVariables and matching on -- SomeSized (v :: Sized.Vector n Int). -- -- Without this, you would otherwise have to use withSized to do -- the same thing: -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc u = withSized u $ \v ->
--       sum (zipWith (+) v (replicate 1))
--   
-- -- Remember that the type of final result of your function (the -- Int, here) must not depend on n. However, the -- types of the intermediate values are allowed to depend on n. -- -- This is especially useful in do blocks, where you can pattern -- match on the unsized results of actions, to use the sized vector in -- the rest of the do block. You also get a KnownNat n -- constraint for the remainder of the do block. -- --
--   -- If you had:
--   getAVector :: IO (Unsized.Vector Int)
--   
--   main :: IO ()
--   main = do
--       SomeSized v <- getAVector -- v is `Sized.Vector n Int`
--       -- get n in scope
--       SomeSized (v :: Sized.Vector n Int) <- getAVector
--       print v
--   
-- -- Remember that the final type of the result of the do block -- ((), here) must not depend on n. However, the -- -- Also useful in ghci, where you can pattern match to get sized vectors -- from unsized vectors. -- --
--   ghci> SomeSized v <- pure (myUnsizedVector :: Unsized.Vector Int)
--                -- ^ v is `Sized.Vector n Int`
--   
-- -- This enables interactive exploration with sized vectors in ghci, and -- is useful for using with other libraries and functions that expect -- sized vectors in an interactive setting. -- -- (Note that as of GHC 8.6, you cannot get the n in scope in -- your ghci session using ScopedTypeVariables, like you can with do -- blocks) -- -- You can also use this as a constructor, to take a sized vector and -- "hide" the size, to produce an unsized vector: -- --
--   SomeSized :: Sized.Vector n a -> Unsized.Vector a
--   
pattern SomeSized :: () => KnownNat n => Vector n a -> Vector a -- | 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. () => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. KnownNat n => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. () => 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. 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, 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. 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. 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. 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) => 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) => 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n m a. KnownNat n => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n m a p. KnownNat n => 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 -- resulting vector is inferred from the type. drop :: forall n m a. KnownNat n => 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. KnownNat n => 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 resulting vectors are -- inferred from the type. splitAt :: forall n m a. KnownNat n => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a p. KnownNat n => 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 the function n times to a 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 the function n times to a 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 -- 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 -- 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, ..., x + (n - 1). The length 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, ..., x + (n - 1). The length 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+2y, ... , x + (n - 1)y. -- The length 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+2y, ... , x + (n - 1)y. -- The length 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 -> [(Finite m, 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. Functor f => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a) -- | Type-safe lens to access (O(1)) and update (O(n)) an -- arbitrary element by its index which should be supplied via -- TypeApplications. ix' :: forall i n a f. (Functor f, KnownNat i, KnownNat n, (i + 1) <= 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. 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. 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 :: (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' :: (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 :: (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' :: (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 product of the elements. product :: Num a => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: Ord a => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: Ord a => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: (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 => 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 :: (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 => 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 :: (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 => (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 => (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 => (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 => (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 (1 + n) a -- | O(n) Haskell-style scan with strict accumulator. scanl' :: (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Scan over a non-empty vector. scanl1 :: (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Scan over a non-empty vector with a strict accumulator. scanl1' :: (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) 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 + 1) b -- | O(n) Right-to-left Haskell-style scan with strict accumulator. scanr' :: (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b -- | O(n) Right-to-left scan over a non-empty vector. scanr1 :: (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator. scanr1' :: (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) 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 resulting 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 resulting 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 -- without 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 -- | Apply a function on two unsized vectors to sized vectors. The function -- must preserve the size of the vectors, this is not checked. zipVectorsUnsafe :: (Vector a -> Vector b -> Vector c) -> Vector n a -> Vector n b -> Vector n c -- | 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 resulting vector size is not known until runtime -- 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. () => 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, 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, 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n k s a. (KnownNat n, Storable a) => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n k s a p. (KnownNat n, 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 -- resulting vector is inferred from the type. drop :: forall n k s a. (KnownNat n, 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n k s a p. (KnownNat n, Storable a) => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m s a. (KnownNat n, 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 rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. (KnownNat n, Storable a) => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Check if two vectors overlap. overlaps :: forall n k s a. 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. (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 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. (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 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. (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 k, PrimMonad m, Storable a) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at the given type-safe positions using -- Finites. swap :: forall n m a. (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. (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 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. (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. (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. (PrimMonad m, Storable a) => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at the given Int positions -- without bounds checking. unsafeSwap :: forall n m a. (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. (PrimMonad m, Storable a) => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next permutation (lexicographically) of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (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 resulting vector size is not known until runtime -- are not exported. module Data.Vector.Storable.Sized -- | Vector specialized to use Storable. type Vector = Vector Vector -- | Pattern synonym that lets you treat an unsized vector as if it -- "contained" a sized vector. If you pattern match on an unsized vector, -- its contents will be the sized vector counterpart. -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc (SomeSized v) =
--       sum (zipWith (+) v (replicate 1))
--           -- ^ here, v is `Sized.Vector n Int`, and we have
--                       `KnownNat n`
--   
-- -- The n type variable will be properly instantiated to whatever -- the length of the vector is, and you will also have a -- KnownNat n instance available. You can get n -- in scope by turning on ScopedTypeVariables and matching on -- SomeSized (v :: Sized.Vector n Int). -- -- Without this, you would otherwise have to use withSized to do -- the same thing: -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc u = withSized u $ \v ->
--       sum (zipWith (+) v (replicate 1))
--   
-- -- Remember that the type of final result of your function (the -- Int, here) must not depend on n. However, the -- types of the intermediate values are allowed to depend on n. -- -- This is especially useful in do blocks, where you can pattern -- match on the unsized results of actions, to use the sized vector in -- the rest of the do block. You also get a KnownNat n -- constraint for the remainder of the do block. -- --
--   -- If you had:
--   getAVector :: IO (Unsized.Vector Int)
--   
--   main :: IO ()
--   main = do
--       SomeSized v <- getAVector -- v is `Sized.Vector n Int`
--       -- get n in scope
--       SomeSized (v :: Sized.Vector n Int) <- getAVector
--       print v
--   
-- -- Remember that the final type of the result of the do block -- ((), here) must not depend on n. However, the -- -- Also useful in ghci, where you can pattern match to get sized vectors -- from unsized vectors. -- --
--   ghci> SomeSized v <- pure (myUnsizedVector :: Unsized.Vector Int)
--                -- ^ v is `Sized.Vector n Int`
--   
-- -- This enables interactive exploration with sized vectors in ghci, and -- is useful for using with other libraries and functions that expect -- sized vectors in an interactive setting. -- -- (Note that as of GHC 8.6, you cannot get the n in scope in -- your ghci session using ScopedTypeVariables, like you can with do -- blocks) -- -- You can also use this as a constructor, to take a sized vector and -- "hide" the size, to produce an unsized vector: -- --
--   SomeSized :: Sized.Vector n a -> Unsized.Vector a
--   
pattern SomeSized :: Storable a => KnownNat n => Vector n a -> Vector a -- | 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. Storable a => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. (KnownNat n, Storable a) => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. 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. (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, 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. (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. (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. (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, 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, 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 resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n m a. (KnownNat n, Storable a) => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n m a p. (KnownNat n, 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 -- resulting vector is inferred from the type. drop :: forall n m a. (KnownNat n, 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. (KnownNat n, Storable a) => p n -> Vector (n + m) a -> Vector m a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m a. (KnownNat n, 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 resulting vector is -- passed explicitly as a Proxy argument. splitAt' :: forall n m a p. (KnownNat n, 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 -- 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 -- 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, ..., x + (n - 1). The length 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, ..., x + (n - 1). The length 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+2y, ..., x + (n - 1)y. -- The length 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+2y, ..., x + (n - 1)y. -- The length 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 -> [(Finite m, 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. (Storable a, Functor f) => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a) -- | Type-safe lens to access (O(1)) and update (O(n)) an -- arbitrary element by its index which should be supplied via -- TypeApplications. ix' :: forall i n a f. (Storable a, Functor f, KnownNat i, KnownNat n, (i + 1) <= 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. (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. (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 => (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 => (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 => (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 => (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 product 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) => 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 => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Storable a, Ord a) => 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 => (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) => 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 => (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) => 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 => (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) => (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) => (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) => (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) => (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 (1 + n) a -- | O(n) Haskell-style scan with strict accumulator. scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Scan over a non-empty vector. scanl1 :: Storable a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Scan over a non-empty vector with a strict accumulator. scanl1' :: Storable a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) 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 + 1) 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 + 1) b -- | O(n) Right-to-left scan over a non-empty vector. scanr1 :: Storable a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator. scanr1' :: Storable a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) 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 resulting 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 resulting 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). () => (Vector a -> Vector b) -> Vector n a -> Vector n b -- | Apply a function on two unsized vectors to sized vectors. The function -- must preserve the size of the vectors, this is not checked. zipVectorsUnsafe :: (Vector a -> Vector b -> Vector c) -> Vector n a -> Vector n b -> Vector n c -- | 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 resulting vector size is not known until runtime -- are not exported. module Data.Vector.Unboxed.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. () => 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, Unbox 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, Unbox 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. Unbox 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. Unbox a => MVector (1 + n) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n k s a. (KnownNat n, Unbox a) => MVector (n + k) s a -> MVector n s a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n k s a p. (KnownNat n, Unbox 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 -- resulting vector is inferred from the type. drop :: forall n k s a. (KnownNat n, Unbox 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n k s a p. (KnownNat n, Unbox a) => p n -> MVector (n + k) s a -> MVector k s a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vectors are inferred -- from the type. splitAt :: forall n m s a. (KnownNat n, Unbox a) => MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m s a p. (KnownNat n, Unbox a) => p n -> MVector (n + m) s a -> (MVector n s a, MVector m s a) -- | O(1) Check if two vectors overlap. overlaps :: forall n k s a. Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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. (PrimMonad m, Unbox 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 k, PrimMonad m, Unbox 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. (PrimMonad m, Unbox 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 k, PrimMonad m, Unbox 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. (PrimMonad m, Unbox 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 k, PrimMonad m, Unbox a) => MVector ((n + k) + 1) (PrimState m) a -> (a -> a) -> p k -> m () -- | O(1) Swap the elements at the given type-safe positions using -- Finites. swap :: forall n m a. (PrimMonad m, Unbox 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. (PrimMonad m, Unbox 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 k, PrimMonad m, Unbox 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. (PrimMonad m, Unbox 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. (PrimMonad m, Unbox 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. (PrimMonad m, Unbox a) => MVector n (PrimState m) a -> (a -> a) -> Int -> m () -- | O(1) Swap the elements at the given Int positions -- without bounds checking. unsafeSwap :: forall n m a. (PrimMonad m, Unbox 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. (PrimMonad m, Unbox a) => MVector n (PrimState m) a -> Int -> a -> m a -- | Compute the next permutation (lexicographically) of a given vector -- in-place. Returns False when the input is the last permutation. nextPermutation :: forall n e m. (Ord e, PrimMonad m, Unbox e) => MVector n (PrimState m) e -> m Bool -- | Set all elements of the vector to the given value. set :: (PrimMonad m, Unbox a) => MVector n (PrimState m) a -> a -> m () -- | Copy a vector. The two vectors may not overlap. copy :: (PrimMonad m, Unbox 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, Unbox 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, Unbox 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, Unbox 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. Unbox 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 class (Vector Vector a, MVector MVector a) => Unbox a instance (Data.Vector.Unboxed.Base.Unbox a, GHC.TypeNats.KnownNat n) => Data.Vector.Unboxed.Base.Unbox (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Unboxed.Base.Vector n a) instance (Data.Vector.Unboxed.Base.Unbox a, GHC.TypeNats.KnownNat n) => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Unboxed.Base.Vector n a) instance (Data.Vector.Unboxed.Base.Unbox a, GHC.TypeNats.KnownNat n) => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Data.Vector.Generic.Sized.Internal.Vector Data.Vector.Unboxed.Base.Vector n a) -- | This module re-exports the functionality in Sized specialized -- to Unboxed. -- -- 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 resulting vector size is not known until runtime -- are not exported. module Data.Vector.Unboxed.Sized -- | Vector specialized to use Unboxed. type Vector = Vector Vector -- | Pattern synonym that lets you treat an unsized vector as if it -- "contained" a sized vector. If you pattern match on an unsized vector, -- its contents will be the sized vector counterpart. -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc (SomeSized v) =
--       sum (zipWith (+) v (replicate 1))
--           -- ^ here, v is `Sized.Vector n Int`, and we have
--                       `KnownNat n`
--   
-- -- The n type variable will be properly instantiated to whatever -- the length of the vector is, and you will also have a -- KnownNat n instance available. You can get n -- in scope by turning on ScopedTypeVariables and matching on -- SomeSized (v :: Sized.Vector n Int). -- -- Without this, you would otherwise have to use withSized to do -- the same thing: -- --
--   testFunc :: Unsized.Vector Int -> Int
--   testFunc u = withSized u $ \v ->
--       sum (zipWith (+) v (replicate 1))
--   
-- -- Remember that the type of final result of your function (the -- Int, here) must not depend on n. However, the -- types of the intermediate values are allowed to depend on n. -- -- This is especially useful in do blocks, where you can pattern -- match on the unsized results of actions, to use the sized vector in -- the rest of the do block. You also get a KnownNat n -- constraint for the remainder of the do block. -- --
--   -- If you had:
--   getAVector :: IO (Unsized.Vector Int)
--   
--   main :: IO ()
--   main = do
--       SomeSized v <- getAVector -- v is `Sized.Vector n Int`
--       -- get n in scope
--       SomeSized (v :: Sized.Vector n Int) <- getAVector
--       print v
--   
-- -- Remember that the final type of the result of the do block -- ((), here) must not depend on n. However, the -- -- Also useful in ghci, where you can pattern match to get sized vectors -- from unsized vectors. -- --
--   ghci> SomeSized v <- pure (myUnsizedVector :: Unsized.Vector Int)
--                -- ^ v is `Sized.Vector n Int`
--   
-- -- This enables interactive exploration with sized vectors in ghci, and -- is useful for using with other libraries and functions that expect -- sized vectors in an interactive setting. -- -- (Note that as of GHC 8.6, you cannot get the n in scope in -- your ghci session using ScopedTypeVariables, like you can with do -- blocks) -- -- You can also use this as a constructor, to take a sized vector and -- "hide" the size, to produce an unsized vector: -- --
--   SomeSized :: Sized.Vector n a -> Unsized.Vector a
--   
pattern SomeSized :: Unbox a => KnownNat n => Vector n a -> Vector a -- | 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. Unbox 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. Unbox a => Vector n a -> (KnownNat n => Proxy n -> r) -> r -- | O(1) Safe indexing using a Finite. index :: forall n a. Unbox a => Vector n a -> Finite n -> a -- | O(1) Safe indexing using a Proxy. index' :: forall n m a p. (KnownNat n, Unbox a) => Vector ((n + m) + 1) a -> p n -> a -- | O(1) Indexing using an Int without bounds checking. unsafeIndex :: forall n a. Unbox a => Vector n a -> Int -> a -- | O(1) Yield the first element of a non-empty vector. head :: forall n a. Unbox a => Vector (1 + n) a -> a -- | O(1) Yield the last element of a non-empty vector. last :: forall n a. Unbox 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. (Unbox 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, Unbox 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. (Unbox 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. (Unbox 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. (Unbox 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, Unbox 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, Unbox 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. Unbox 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. Unbox a => Vector (1 + n) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is inferred from the type. take :: forall n m a. (KnownNat n, Unbox a) => Vector (n + m) a -> Vector n a -- | O(1) Yield the first n elements. The resulting vector -- always contains this many elements. The length of the resulting vector -- is given explicitly as a Proxy argument. take' :: forall n m a p. (KnownNat n, Unbox 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 -- resulting vector is inferred from the type. drop :: forall n m a. (KnownNat n, Unbox 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 -- resulting vector is givel explicitly as a Proxy argument. drop' :: forall n m a p. (KnownNat n, Unbox a) => p n -> Vector (n + m) a -> Vector m a -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The lengths of the resulting vector are inferred from -- the type. splitAt :: forall n m a. (KnownNat n, Unbox a) => Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Yield the first n elements, paired with the rest, -- without copying. The length of the first resulting vector is passed -- explicitly as a Proxy argument. splitAt' :: forall n m a p. (KnownNat n, Unbox a) => p n -> Vector (n + m) a -> (Vector n a, Vector m a) -- | O(1) Empty vector. empty :: forall a. Unbox a => Vector 0 a -- | O(1) Vector with exactly one element. singleton :: forall a. Unbox 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. (Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox a) => p n -> (Finite n -> a) -> Vector n a -- | O(n) Apply the function n times to a value. Zeroth -- element is original value. The length is inferred from the type. iterateN :: forall n a. (KnownNat n, Unbox a) => (a -> a) -> a -> Vector n a -- | O(n) Apply the function n times to a value. Zeroth -- element is original value. The length is given explicitly as a -- Proxy argument. iterateN' :: forall n a p. (KnownNat n, Unbox 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, Unbox 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, Unbox 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, Unbox 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, Unbox 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 -- is inferred from the type. unfoldrN :: forall n a b. (KnownNat n, Unbox 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 -- is given explicitly as a Proxy argument. unfoldrN' :: forall n a b p. (KnownNat n, Unbox a) => p n -> (b -> (a, b)) -> b -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1, ..., x + (n - 1). The length is -- inferred from the type. enumFromN :: forall n a. (KnownNat n, Unbox a, Num a) => a -> Vector n a -- | O(n) Yield a vector of length n containing the values -- x, x+1, ..., x + (n - 1). The length is -- given explicitly as a Proxy argument. enumFromN' :: forall n a p. (KnownNat n, Unbox 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+2y, ..., x + (n - 1)y. -- The length is inferred from the type. enumFromStepN :: forall n a. (KnownNat n, Unbox a, Num a) => a -> a -> Vector n a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+2y, ..., x + (n - 1)y. -- The length is given explicitly as a Proxy argument. enumFromStepN' :: forall n a p. (KnownNat n, Unbox a, Num a) => a -> a -> p n -> Vector n a -- | O(n) Prepend an element. cons :: forall n a. Unbox a => a -> Vector n a -> Vector (1 + n) a -- | O(n) Append an element. snoc :: forall n a. Unbox a => Vector n a -> a -> Vector (n + 1) a -- | O(m+n) Concatenate two vectors. (++) :: forall n m a. Unbox 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 :: Unbox 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>
--   
(//) :: Unbox 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 :: Unbox 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_ :: Unbox a => Vector m a -> Vector n Int -> Vector n a -> Vector m a -- | Same as (//) but without bounds checking. unsafeUpd :: Unbox a => Vector m a -> [(Int, a)] -> Vector m a -- | Same as update but without bounds checking. unsafeUpdate :: Unbox a => Vector m a -> Vector n (Int, a) -> Vector m a -- | Same as update_ but without bounds checking. unsafeUpdate_ :: Unbox 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 :: Unbox a => (a -> b -> a) -> Vector m a -> [(Finite m, 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 :: (Unbox a, Unbox 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_ :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | Same as accum but without bounds checking. unsafeAccum :: Unbox a => (a -> b -> a) -> Vector m a -> [(Int, b)] -> Vector m a -- | Same as accumulate but without bounds checking. unsafeAccumulate :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector m a -> Vector n (Int, b) -> Vector m a -- | Same as accumulate_ but without bounds checking. unsafeAccumulate_ :: (Unbox a, Unbox b) => (a -> b -> a) -> Vector m a -> Vector n Int -> Vector n b -> Vector m a -- | O(n) Reverse a vector. reverse :: Unbox 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 :: Unbox a => Vector m a -> Vector n Int -> Vector n a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: Unbox 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. (Unbox a, Functor f) => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a) -- | Type-safe lens to access (O(1)) and update (O(n)) an -- arbitrary element by its index which should be supplied via -- TypeApplications. ix' :: forall i n a f. (Unbox a, Functor f, KnownNat i, KnownNat n, (i + 1) <= 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. (Unbox 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. (Unbox 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 :: (Unbox a, Unbox (Finite n)) => Vector n a -> Vector n (Finite n, a) -- | O(n) Map a function over a vector. map :: (Unbox a, Unbox b) => (a -> b) -> Vector n a -> Vector n b -- | O(n) Apply a function to every element of a vector and its -- index. imap :: (Unbox a, Unbox 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 :: (Unbox a, Unbox 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, Unbox a, Unbox 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, Unbox a, Unbox 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, Unbox 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, Unbox 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, Unbox a, Unbox 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, Unbox a) => Vector n a -> (a -> m b) -> m () -- | O(n) Zip two vectors of the same length with the given -- function. zipWith :: (Unbox a, Unbox b, Unbox c) => (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c -- | Zip three vectors with the given function. zipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d) => (a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d zipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => (a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e zipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox 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 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox 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 :: (Unbox a, Unbox b, Unbox c) => (Finite n -> a -> b -> c) -> Vector n a -> Vector n b -> Vector n c izipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d) => (Finite n -> a -> b -> c -> d) -> Vector n a -> Vector n b -> Vector n c -> Vector n d izipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => (Finite n -> a -> b -> c -> d -> e) -> Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e izipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox 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 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox 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 :: (Unbox a, Unbox b) => Vector n a -> Vector n b -> Vector n (a, b) zip3 :: (Unbox a, Unbox b, Unbox c) => Vector n a -> Vector n b -> Vector n c -> Vector n (a, b, c) zip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n (a, b, c, d) zip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector n a -> Vector n b -> Vector n c -> Vector n d -> Vector n e -> Vector n (a, b, c, d, e) zip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox 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, Unbox a, Unbox b, Unbox 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, Unbox a, Unbox b, Unbox 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, Unbox a, Unbox 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, Unbox a, Unbox b) => (Finite n -> a -> b -> m c) -> Vector n a -> Vector n b -> m () -- | O(min(m,n)) Unzip a vector of pairs. unzip :: (Unbox a, Unbox b) => Vector n (a, b) -> (Vector n a, Vector n b) unzip3 :: (Unbox a, Unbox b, Unbox c) => Vector n (a, b, c) -> (Vector n a, Vector n b, Vector n c) unzip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => Vector n (a, b, c, d) -> (Vector n a, Vector n b, Vector n c, Vector n d) unzip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector n (a, b, c, d, e) -> (Vector n a, Vector n b, Vector n c, Vector n d, Vector n e) unzip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox 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 :: (Unbox 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 :: (Unbox 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 :: Unbox 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 :: Unbox 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 :: (Unbox a, Eq a) => a -> Vector n a -> Maybe (Finite n) -- | O(n) Left fold. foldl :: Unbox b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors. foldl1 :: Unbox a => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Left fold with strict accumulator. foldl' :: Unbox b => (a -> b -> a) -> a -> Vector n b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator. foldl1' :: Unbox a => (a -> a -> a) -> Vector (1 + n) a -> a -- | O(n) Right fold. foldr :: Unbox a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors. foldr1 :: Unbox a => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Right fold with a strict accumulator. foldr' :: Unbox a => (a -> b -> b) -> b -> Vector n a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator. foldr1' :: Unbox a => (a -> a -> a) -> Vector (n + 1) a -> a -- | O(n) Left fold (function applied to each element and its -- index). ifoldl :: Unbox 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' :: Unbox b => (a -> Finite n -> b -> a) -> a -> Vector n b -> a -- | O(n) Right fold (function applied to each element and its -- index). ifoldr :: Unbox 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' :: Unbox a => (Finite n -> a -> b -> b) -> b -> Vector n a -> b -- | O(n) Check if all elements satisfy the predicate. all :: Unbox a => (a -> Bool) -> Vector n a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Unbox 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 :: (Unbox a, Num a) => Vector n a -> a -- | O(n) Compute the product of the elements. product :: (Unbox a, Num a) => Vector n a -> a -- | O(n) Yield the maximum element of the non-empty vector. maximum :: (Unbox a, Ord a) => Vector (n + 1) a -> a -- | O(n) Yield the maximum element of the non-empty vector -- according to the given comparison function. maximumBy :: Unbox a => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector. minimum :: (Unbox a, Ord a) => Vector (n + 1) a -> a -- | O(n) Yield the minimum element of the non-empty vector -- according to the given comparison function. minimumBy :: Unbox a => (a -> a -> Ordering) -> Vector (n + 1) a -> a -- | O(n) Yield the index of the maximum element of the non-empty -- vector. maxIndex :: (Unbox a, Ord a) => 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 :: Unbox a => (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 :: (Unbox a, Ord a) => 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 :: Unbox a => (a -> a -> Ordering) -> Vector (n + 1) a -> Finite (n + 1) -- | O(n) Monadic fold. foldM :: (Monad m, Unbox 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, Unbox b) => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a -- | O(n) Monadic fold over non-empty vectors. fold1M :: (Monad m, Unbox a) => (a -> a -> m a) -> Vector (1 + n) a -> m a -- | O(n) Monadic fold with strict accumulator. foldM' :: (Monad m, Unbox 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, Unbox 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, Unbox a) => (a -> a -> m a) -> Vector (n + 1) a -> m a -- | O(n) Monadic fold that discards the result. foldM_ :: (Monad m, Unbox 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, Unbox 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, Unbox a) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result. foldM'_ :: (Monad m, Unbox 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, Unbox 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, Unbox a) => (a -> a -> m a) -> Vector (n + 1) a -> m () -- | Evaluate each action and collect the results. sequence :: (Monad m, Unbox a, Unbox (m a)) => Vector n (m a) -> m (Vector n a) -- | Evaluate each action and discard the results. sequence_ :: (Monad m, Unbox (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 :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Prescan with strict accumulator. prescanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan. postscanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Scan with strict accumulator. postscanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector n a -- | O(n) Haskell-style scan. scanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Haskell-style scan with strict accumulator. scanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a -- | O(n) Scan over a non-empty vector. scanl1 :: Unbox a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Scan over a non-empty vector with a strict accumulator. scanl1' :: Unbox a => (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a -- | O(n) Right-to-left prescan. prescanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left prescan with strict accumulator. prescanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan. postscanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left scan with strict accumulator. postscanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector n b -- | O(n) Right-to-left Haskell-style scan. scanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b -- | O(n) Right-to-left Haskell-style scan with strict accumulator. scanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b -- | O(n) Right-to-left scan over a non-empty vector. scanr1 :: Unbox a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator. scanr1' :: Unbox a => (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a -- | O(n) Convert a vector to a list. toList :: Unbox a => Vector n a -> [a] -- | O(n) Convert a list to a vector. fromList :: (Unbox 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 resulting vector is inferred from the type. fromListN :: forall n a. (Unbox 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 resulting vector is given explicitly as a -- Proxy argument. fromListN' :: forall n a p. (Unbox 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. Unbox a => [a] -> (forall n. KnownNat n => Vector n a -> r) -> r -- | O(n) Yield an immutable copy of the mutable vector. freeze :: (PrimMonad m, Unbox a) => MVector n (PrimState m) a -> m (Vector n a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: (PrimMonad m, Unbox a) => Vector n a -> m (MVector n (PrimState m) a) -- | O(n) Copy an immutable vector into a mutable one. copy :: (PrimMonad m, Unbox 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, Unbox 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, Unbox 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. (Unbox 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. Unbox 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). () => (Vector a -> Vector b) -> Vector n a -> Vector n b -- | Apply a function on two unsized vectors to sized vectors. The function -- must preserve the size of the vectors, this is not checked. zipVectorsUnsafe :: (Vector a -> Vector b -> Vector c) -> Vector n a -> Vector n b -> Vector n c class (Vector Vector a, MVector MVector a) => Unbox a