HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulevector-sized-1.6.1Haskell2010

Data.Vector.Generic.Sized

This module reexports the functionality in Data.Vector.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.

Contents
  1. Accessors
  2. Length information
  3. Indexing
  4. Monadic indexing
  5. Extracting subvectors (slicing)
  6. Construction
  7. Initialization
  8. Monadic initialization
  9. Unfolding
  10. Enumeration
  11. Concatenation
  12. Restricting memory usage
  13. Modifying vectors
  14. Bulk updates
  15. Accumulations
  16. Permutations
  17. Lenses
  18. Elementwise operations
  19. Indexing
  20. Mapping
  21. Monadic mapping
  22. Zipping
  23. Monadic zipping
  24. Unzipping
  25. Working with predicates
  26. Searching
  27. Folding
  28. Specialised folds
  29. Monadic folds
  30. Monadic sequencing
  31. Prefix sums (scans)
  32. Conversions
  33. Lists
  34. Other Vector types
  35. Mutable vectors
  36. Unsized Vectors
Synopsis
newtypenewtype Vector (v :: Type -> Type) (n :: Nat) a

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!

Instances41FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, Monad, Functor, Applicative, …
  • (Unbox a, KnownNat n) => MVector MVector (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Unboxed.Mutable.Sized · orphan
  • (Unbox a, KnownNat n) => Vector Vector (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Unboxed.Mutable.Sized · orphan
  • FoldableWithIndex (Finite n) (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • FunctorWithIndex (Finite n) (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • TraversableWithIndex (Finite n) (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • KnownNat n => Monad (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    Treats a Vector n a as, essentially, a Finite n -> a, and emulates the Monad instance for that function.

    join :: Vector n (Vector n a) -> Vector n a gets the diagonal from a square "matrix".

  • Functor v => Functor (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • KnownNat n => Applicative (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    The Applicative instance for sized vectors does not have the same behaviour as the Applicative instance for the unsized vectors found in the vectors package. The instance defined here has the same behaviour as the ZipList instance.

  • Foldable v => Foldable (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • Traversable v => Traversable (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • Eq1 v => Eq1 (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • Ord1 v => Ord1 (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • Show1 v => Show1 (Vector v n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • KnownNat n => Distributive (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (KnownNat n, n ~ (1 + m)) => Comonad (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    Non-empty sized vectors are lawful comonads.

    extract is head

    duplicate generates all unique sequences of a vector with the same length as it, using wrap-around.

    e.g. duplicate [1,2,3,4,5] = [[1,2,3,4,5], [2,3,4,5,1], [3,4,5,1,2], [4,5,1,2,3], [5,1,2,3,4]]

  • (KnownNat n, n ~ (1 + m)) => ComonadApply (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • KnownNat n => Representable (Vector Vector n)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • Eq (v a) => Eq (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (Vector v a, Floating a, KnownNat n) => Floating (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Vector v a, Fractional a, KnownNat n) => Fractional (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Typeable v, Typeable a, KnownNat n, Data (v a)) => Data (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (Vector v a, Num a, KnownNat n) => Num (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • Ord (v a) => Ord (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (KnownNat n, Vector v a, Read (v a)) => Read (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • Show (v a) => Show (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (Ix a, Ord (v a), Vector v a) => Ix (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (Semigroup g, Vector v g) => Semigroup (Vector v n g)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    The Semigroup instance for sized vectors does not have the same behaviour as the Semigroup instance for the unsized vectors found in the vectors package. This instance has (<>) = zipWith (<>), but vectors uses concatentation.

  • (Monoid m, Vector v m, KnownNat n) => Monoid (Vector v n m)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    The Monoid instance for sized vectors does not have the same behaviour as the Monoid instance for the unsized vectors found in the vectors package. This instance has mempty = replicate mempty and mappend = zipWith mappend, where the vectors instance uses the empty vector and concatenation.

    If mempty is not necessary, using the Semigroup instance over this Monoid will dodge the KnownNat constraint.

  • (Vector v a, Bits (v a), Bits a, KnownNat n) => Bits (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    Only usable if v a is itself an instance of Bits, like in the case with the bitvec library Bit type for unboxed vectors.

  • (Vector v a, Bits (v a), FiniteBits a, KnownNat n) => FiniteBits (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    Treats a bit vector as n times the size of the stored bits, reflecting the Bits instance; does not necessarily reflect exact in-memory representation. See Storable instance to get information on the actual in-memry representation.

  • (KnownNat n, Storable a, Vector v a) => Storable (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan

    Any sized vector containing Storable elements is itself Storable.

  • NFData (v a) => NFData (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized.Internal
  • (Vector v a, Binary a, KnownNat n) => Binary (Vector v n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Eq a, Hashable a) => Hashable (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Eq a, Hashable a, Storable a) => Hashable (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Eq a, Hashable a, Unbox a) => Hashable (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • (Unbox a, KnownNat n) => Unbox (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Unboxed.Mutable.Sized · orphan

    This instance allows to define sized matrices and tensors backed by continuous memory segments, which reduces memory allocations and relaxes pressure on garbage collector.

  • type Mutable (Vector v n) = MVector (Mutable v) nDefined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
  • data MVector s (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Unboxed.Mutable.Sized · orphan
  • data Vector (Vector Vector n a)Defined in vector-sized-1.6.1 · Data.Vector.Unboxed.Mutable.Sized · orphan
  • type Rep (Vector Vector n) = Finite nDefined in vector-sized-1.6.1 · Data.Vector.Generic.Sized · orphan
patternpattern SomeSized :: Vector v a => KnownNat n => Vector v n a -> v 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).

newtypenewtype MVector (v :: Type -> Type -> Type) (n :: Nat) s 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!

Instances3Data, Storable, NFData

Accessors

Length information

valuelength' :: Vector v n a -> Proxy n

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.

valueknownLength
  1. :: Vector v a
  2. => Vector v n a

    a vector of some (potentially unknown) length

  3. -> (KnownNat n => r)

    a value that depends on knowing the vector's length

  4. -> r

    the value computed with the length

O(1) Reveal a KnownNat instance for a vector's length, determined at runtime.

valueknownLength'
  1. :: Vector v a
  2. => Vector v n a

    a vector of some (potentially unknown) length

  3. -> (KnownNat n => Proxy n -> r)

    a value that depends on knowing the vector's length, which is given as a Proxy

  4. -> r

    the value computed with the length

O(1) Reveal a KnownNat instance and Proxy for a vector's length, determined at runtime.

Indexing

Monadic indexing

valueindexM :: (Vector v a, Monad m) => Vector v n a -> Finite n -> m 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.

valueheadM :: (Vector v a, Monad m) => Vector v (1 + n) a -> 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.

valuelastM :: (Vector v a, Monad m) => Vector v (n + 1) a -> m a

O(1) Yield the last element of a non-empty vector in a monad. See the documentation for indexM for an explanation of why this is useful.

Extracting subvectors (slicing)

valuetake :: (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 inferred from the type.

valuetake'
  1. :: (KnownNat n, Vector v a)
  2. => p n
  3. -> Vector v (n + m) a
  4. -> 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.

valuedrop :: (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 inferred from the type.

valuedrop'
  1. :: (KnownNat n, Vector v a)
  2. => p n
  3. -> Vector v (n + m) a
  4. -> 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.

valuesplitAt
  1. :: (KnownNat n, Vector v a)
  2. => Vector v (n + m) a
  3. -> (Vector v n 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.

valuesplitAt'
  1. :: (KnownNat n, Vector v a)
  2. => p n
  3. -> Vector v (n + m) a
  4. -> (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.

Construction

Initialization

valuefromTuple
  1. :: (Vector v a, IndexedListLiterals input length a, KnownNat length)
  2. => input
  3. -> Vector v length a

O(n) Construct a vector in a type-safe manner using a tuple. fromTuple (1,2) :: Vector v 2 Int fromTuple ("hey", "what's", "going", "on") :: Vector v 4 String

patternpattern Build :: Vector v a => BuildVector n a -> Vector v n a

O(n) Construct a vector in a type-safe manner using a sized linked list. Build (1 :< 2 :< 3 :< Nil) :: Vector v 3 Int Build ("not" :< "much" :< Nil) :: Vector v 2 String Can also be used as a pattern.

valuereplicate :: (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 inferred from the type.

valuegenerate :: (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 inferred from the type.

valueiterateN :: (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 inferred from the type.

valueiterateN'
  1. :: (KnownNat n, Vector v a)
  2. => p n
  3. -> a -> a
  4. -> a
  5. -> 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.

Monadic initialization

Unfolding

valueunfoldrN :: (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 inferred from the type.

valueunfoldrN'
  1. :: (KnownNat n, Vector v a)
  2. => p n
  3. -> b -> (a, b)
  4. -> b
  5. -> 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.

Enumeration

valueenumFromN :: (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 inferred from the type.

valueenumFromStepN :: (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 inferred from the type.

Concatenation

Restricting memory usage

valueforce :: Vector v a => Vector v n a -> Vector v n 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.

Modifying vectors

Bulk updates

value(//)
  1. :: Vector v a
  2. => Vector v m a

    initial vector (of length m)

  3. -> [(Finite m, a)]

    list of index/value pairs (of length n)

  4. -> Vector v m 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>
valueupdate
  1. :: (Vector v a, Vector v (Int, a))
  2. => Vector v m a

    initial vector (of length m)

  3. -> Vector v n (Int, a)

    vector of index/value pairs (of length n)

  4. -> 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>
valueupdate_
  1. :: (Vector v a, Vector v Int)
  2. => Vector v m a

    initial vector (of length m)

  3. -> Vector v n Int

    index vector (of length n)

  4. -> Vector v n a

    value vector (of length n)

  5. -> 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)

Accumulations

valueaccum
  1. :: Vector v a
  2. => (a -> b -> a)

    accumulating function f

  3. -> Vector v m a

    initial vector (of length m)

  4. -> [(Finite m, b)]

    list of index/value pairs (of length n)

  5. -> 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>
valueaccumulate
  1. :: (Vector v a, Vector v (Int, b))
  2. => (a -> b -> a)

    accumulating function f

  3. -> Vector v m a

    initial vector (of length m)

  4. -> Vector v n (Int, b)

    vector of index/value pairs (of length n)

  5. -> 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>
valueaccumulate_
  1. :: (Vector v a, Vector v Int, Vector v b)
  2. => (a -> b -> a)

    accumulating function f

  3. -> Vector v m a

    initial vector (of length m)

  4. -> Vector v n Int

    index vector (of length n)

  5. -> Vector v n b

    value vector (of length n)

  6. -> 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)
valueunsafeAccum
  1. :: Vector v a
  2. => (a -> b -> a)

    accumulating function f

  3. -> Vector v m a

    initial vector (of length m)

  4. -> [(Int, b)]

    list of index/value pairs (of length n)

  5. -> Vector v m a

Same as accum but without bounds checking.

Permutations

valuebackpermute
  1. :: (Vector v a, Vector v Int)
  2. => Vector v m a

    xs value vector

  3. -> Vector v n Int

    is index vector (of length n)

  4. -> 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>

Lenses

Elementwise operations

Indexing

Mapping

valueconcatMap
  1. :: (Vector v a, Vector v' b)
  2. => a -> Vector v' m b
  3. -> Vector v n a
  4. -> Vector v' (n * m) 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.

Monadic mapping

valuemapM_ :: (Monad m, Vector v a) => (a -> m b) -> Vector v n a -> m ()

O(n) Apply the monadic action to all elements of a vector and ignore the results.

valueimapM_
  1. :: (Monad m, Vector v a)
  2. => Finite n -> a -> m b
  3. -> Vector v n a
  4. -> m ()

O(n) Apply the monadic action to every element of a vector and its index, ignoring the results.

valueforM_ :: (Monad m, Vector v a) => Vector v n a -> (a -> m b) -> m ()

O(n) Apply the monadic action to all elements of a vector and ignore the results. Equivalent to flip mapM_.

Zipping

Monadic zipping

Unzipping

Working with predicates

Searching

Folding

valuefoldl1' :: Vector v a => (a -> a -> a) -> Vector v (1 + n) a -> a

O(n) Left fold on non-empty vectors with strict accumulator.

valuefoldr1' :: Vector v a => (a -> a -> a) -> Vector v (n + 1) a -> a

O(n) Right fold on non-empty vectors with strict accumulator.

valueifoldl :: Vector v b => (a -> Finite n -> b -> a) -> a -> Vector v n b -> a

O(n) Left fold (function applied to each element and its index).

valueifoldl' :: 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).

valueifoldr :: Vector v a => (Finite n -> a -> b -> b) -> b -> Vector v n a -> b

O(n) Right fold (function applied to each element and its index).

valueifoldr' :: 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).

Specialised folds

valuemaximumBy :: Vector v a => (a -> a -> Ordering) -> Vector v (n + 1) a -> a

O(n) Yield the maximum element of the non-empty vector according to the given comparison function.

valueminimumBy :: Vector v a => (a -> a -> Ordering) -> Vector v (n + 1) a -> a

O(n) Yield the minimum element of the non-empty vector according to the given comparison function.

Monadic folds

valueifoldM'
  1. :: (Monad m, Vector v b)
  2. => a -> Finite n -> b -> m a
  3. -> a
  4. -> Vector v n b
  5. -> m a

O(n) Monadic fold with strict accumulator (action applied to each element and its index).

valueifoldM_
  1. :: (Monad m, Vector v b)
  2. => a -> Finite n -> b -> m a
  3. -> a
  4. -> Vector v n b
  5. -> m ()

O(n) Monadic fold that discards the result (action applied to each element and its index).

valuefoldM'_
  1. :: (Monad m, Vector v b)
  2. => a -> b -> m a
  3. -> a
  4. -> Vector v n b
  5. -> m ()

O(n) Monadic fold with strict accumulator that discards the result.

valueifoldM'_
  1. :: (Monad m, Vector v b)
  2. => a -> Finite n -> b -> m a
  3. -> a
  4. -> Vector v n b
  5. -> m ()

O(n) Monadic fold with strict accumulator that discards the result (action applied to each element and its index).

valuefold1M'_
  1. :: (Monad m, Vector v a)
  2. => a -> a -> m a
  3. -> Vector v (n + 1) a
  4. -> m ()

O(n) Monad fold over non-empty vectors with strict accumulator that discards the result.

Monadic sequencing

Prefix sums (scans)

Conversions

Lists

valuewithSizedList
  1. :: Vector v a
  2. => [a]
  3. -> forall (n :: Nat). KnownNat n => Vector v n a -> r
  4. -> r

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

Other Vector types

Mutable vectors

Unsized Vectors

valuewithSized
  1. :: Vector v a
  2. => v a
  3. -> forall (n :: Nat). KnownNat n => Vector v n a -> r
  4. -> r

Takes a Data.Vector.Generic.Vector and returns a continuation providing a Data.Vector.Generic.Sized with a size parameter n that is determined at runtime based on the length of the input vector.

Essentially converts a Data.Vector.Generic.Vector into a Vector with the correct size parameter n.

valuewithVectorUnsafe :: (v a -> w b) -> Vector v n a -> Vector w n b

Apply a function on unsized vectors to a sized vector. The function must preserve the size of the vector, this is not checked.

valuezipVectorsUnsafe
  1. :: u a -> v b -> w c
  2. -> Vector u n a
  3. -> Vector v n b
  4. -> Vector w n c

Apply a function on two unsized vectors to sized vectors. The function must preserve the size of the vectors, this is not checked.

Orphan instances

22 instances