HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulevector-sized-1.6.1Haskell2010

Data.Vector.Sized

This module re-exports the functionality in Data.Vector.Generic.Sized specialized to Data.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.

  • 3 types
  • 176 values
patternpattern SomeSized :: () => KnownNat n => Vector n a -> Vector 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`
    -- 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
typetype MVector = MVector MVector
#

Data.Vector.Generic.Mutable.Sized.Vector specialized to use Data.Vector.Storable.Mutable.

Accessors

0 declarations

Length information

valuelength' :: Vector 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 n a

    a vector of some (potentially unknown) length

  2. -> (KnownNat n => r)

    a value that depends on knowing the vector's length

  3. -> r

    the value computed with the length

#

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

valueknownLength'
  1. :: Vector n a

    a vector of some (potentially unknown) length

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

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

  3. -> r

    the value computed with the length

#

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

Indexing

valuehead :: Vector (1 + n) a -> a
#

O(1) Yield the first element of a non-empty vector.

valuelast :: Vector (n + 1) a -> a
#

O(1) Yield the last element of a non-empty vector.

Monadic indexing

valueindexM :: Monad m => Vector n a -> Finite n -> m a
#

O(1) Safe indexing in a monad. See the documentation for indexM for an explanation of why this is useful.

valueindexM' :: (KnownNat n, Monad m) => Vector (n + k) a -> p 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.

valueunsafeIndexM :: Monad m => Vector n a -> Int -> m a
#

O(1) Indexing using an Int without bounds checking. See the documentation for indexM for an explanation of why this is useful.

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

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

Extracting subvectors (slicing)

valueslice
  1. :: (KnownNat i, KnownNat n)
  2. => p i

    starting index

  3. -> Vector ((i + n) + m) a
  4. -> Vector n a
#

O(1) Yield a slice of the vector without copying it with an inferred length argument.

valueslice'
  1. :: (KnownNat i, KnownNat n)
  2. => p i

    starting index

  3. -> p n

    length

  4. -> Vector ((i + n) + m) a
  5. -> Vector n a
#

O(1) Yield a slice of the vector without copying it with an explicit length argument.

valueinit :: Vector (n + 1) a -> Vector n a
#

O(1) Yield all but the last element of a non-empty vector without copying.

valuetail :: Vector (1 + n) a -> Vector n a
#

O(1) Yield all but the first element of a non-empty vector without copying.

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

valuetake' :: KnownNat n => p 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.

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

valuedrop' :: KnownNat n => p 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.

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

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

Construction

0 declarations

Initialization

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

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

patternpattern Build :: BuildVector n a -> Vector n a
#

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

valuereplicate :: KnownNat n => a -> Vector n a
#

O(n) Construct a vector with the same element in each position where the length is inferred from the type.

valuereplicate' :: KnownNat n => p 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.

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

valuegenerate' :: KnownNat n => p 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.

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

valueiterateN' :: KnownNat n => p 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.

Monadic initialization

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

valuereplicateM' :: (KnownNat n, Monad m) => p n -> 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.

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

valuegenerateM'
  1. :: (KnownNat n, Monad m)
  2. => p n
  3. -> Finite n -> m a
  4. -> 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.

Unfolding

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

valueunfoldrN' :: KnownNat n => p 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.

Enumeration

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

valueenumFromN' :: (KnownNat n, Num a) => a -> p n -> 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.

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

valueenumFromStepN' :: (KnownNat n, Num a) => 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 given explicitly as a Proxy argument.

Concatenation

Restricting memory usage

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

0 declarations

Bulk updates

value(//)
  1. :: Vector m a

    initial vector (of length m)

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

    list of index/value pairs (of length n)

  3. -> Vector 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 m a

    initial vector (of length m)

  2. -> Vector n (Int, a)

    vector of index/value pairs (of length n)

  3. -> 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>
valueupdate_
  1. :: Vector m a

    initial vector (of length m)

  2. -> Vector n Int

    index vector (of length n)

  3. -> Vector n a

    value vector (of length n)

  4. -> 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)
valueunsafeUpd
  1. :: Vector m a

    initial vector (of length m)

  2. -> [(Int, a)]

    list of index/value pairs (of length n)

  3. -> Vector m a
#

Same as (//) but without bounds checking.

Accumulations

valueaccum
  1. :: (a -> b -> a)

    accumulating function f

  2. -> Vector m a

    initial vector (of length m)

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

    list of index/value pairs (of length n)

  4. -> 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>
valueaccumulate
  1. :: (a -> b -> a)

    accumulating function f

  2. -> Vector m a

    initial vector (of length m)

  3. -> Vector n (Int, b)

    vector of index/value pairs (of length n)

  4. -> 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>
valueaccumulate_
  1. :: (a -> b -> a)

    accumulating function f

  2. -> Vector m a

    initial vector (of length m)

  3. -> Vector n Int

    index vector (of length n)

  4. -> Vector n b

    value vector (of length n)

  5. -> 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)
valueunsafeAccum
  1. :: (a -> b -> a)

    accumulating function f

  2. -> Vector m a

    initial vector (of length m)

  3. -> [(Int, b)]

    list of index/value pairs (of length n)

  4. -> Vector m a
#

Same as accum but without bounds checking.

Permutations

valuebackpermute
  1. :: Vector m a

    xs value vector

  2. -> Vector n Int

    is index vector (of length n)

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

Lenses

4 declarations
valueix :: Functor f => Finite n -> (a -> f a) -> Vector n a -> f (Vector n a)
#

Lens to access (O(1)) and update (O(n)) an arbitrary element by its index.

valueix'
  1. :: (Functor f, KnownNat i, KnownNat n, (i + 1) <= n)
  2. => a -> f a
  3. -> Vector n a
  4. -> 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.

value_head :: Functor f => (a -> f a) -> Vector (1 + n) a -> f (Vector (1 + n) a)
#

Lens to access (O(1)) and update (O(n)) the first element of a non-empty vector.

value_last :: Functor f => (a -> f a) -> Vector (n + 1) a -> f (Vector (n + 1) a)
#

Lens to access (O(1)) and update (O(n)) the last element of a non-empty vector.

Elementwise operations

0 declarations

Indexing

Mapping

valuemap :: (a -> b) -> Vector n a -> Vector n b
#

O(n) Map a function over a vector.

valueimap :: (Finite n -> a -> b) -> Vector n a -> Vector n b
#

O(n) Apply a function to every element of a vector and its index.

valueconcatMap :: (a -> Vector m b) -> Vector n a -> Vector (n * m) 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.

Monadic mapping

valuemapM :: Monad m => (a -> m b) -> Vector n a -> m (Vector n b)
#

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

valueimapM :: Monad m => (Finite n -> 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.

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

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

valueimapM_ :: Monad m => (Finite n -> 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.

valueforM :: Monad m => Vector n a -> (a -> m b) -> m (Vector n b)
#

O(n) Apply the monadic action to all elements of the vector, yielding a vector of results. Equvalent to flip mapM.

valueforM_ :: Monad m => Vector 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

valuezipWith :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c
#

O(n) Zip two vectors of the same length with the given function.

valueizipWith
  1. :: Finite n -> a -> b -> c
  2. -> Vector n a
  3. -> Vector n b
  4. -> Vector n c
#

O(n) Zip two vectors of the same length with a function that also takes the elements' indices).

Monadic zipping

valuezipWithM
  1. :: Monad m
  2. => a -> b -> m c
  3. -> Vector n a
  4. -> Vector n b
  5. -> m (Vector n c)
#

O(n) Zip the two vectors of the same length with the monadic action and yield a vector of results.

valueizipWithM
  1. :: Monad m
  2. => Finite n -> a -> b -> m c
  3. -> Vector n a
  4. -> Vector n b
  5. -> 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.

valuezipWithM_ :: Monad m => (a -> b -> m c) -> Vector n a -> Vector n b -> m ()
#

O(n) Zip the two vectors with the monadic action and ignore the results.

valueizipWithM_
  1. :: Monad m
  2. => Finite n -> a -> b -> m c
  3. -> Vector n a
  4. -> Vector n b
  5. -> m ()
#

O(n) Zip the two vectors with a monadic action that also takes the element index and ignore the results.

Unzipping

Working with predicates

0 declarations

Searching

valueelem :: Eq a => a -> Vector n a -> Bool
#

O(n) Check if the vector contains an element.

valuenotElem :: Eq a => a -> Vector n a -> Bool
#

O(n) Check if the vector does not contain an element (inverse of elem).

Folding

12 declarations
valuefoldl :: (a -> b -> a) -> a -> Vector n b -> a
#

O(n) Left fold.

valuefoldl1 :: (a -> a -> a) -> Vector (1 + n) a -> a
#

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

valuefoldl' :: (a -> b -> a) -> a -> Vector n b -> a
#

O(n) Left fold with strict accumulator.

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

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

valuefoldr :: (a -> b -> b) -> b -> Vector n a -> b
#

O(n) Right fold.

valuefoldr1 :: (a -> a -> a) -> Vector (n + 1) a -> a
#

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

valuefoldr' :: (a -> b -> b) -> b -> Vector n a -> b
#

O(n) Right fold with a strict accumulator.

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

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

valueifoldl :: (a -> Finite n -> b -> a) -> a -> Vector n b -> a
#

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

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

valueifoldr :: (Finite n -> a -> b -> b) -> b -> Vector n a -> b
#

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

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

Specialised folds

valueall :: (a -> Bool) -> Vector n a -> Bool
#

O(n) Check if all elements satisfy the predicate.

valueany :: (a -> Bool) -> Vector n a -> Bool
#

O(n) Check if any element satisfies the predicate.

valuesum :: Num a => Vector n a -> a
#

O(n) Compute the sum of the elements.

valueproduct :: Num a => Vector n a -> a
#

O(n) Compute the product of the elements.

valuemaximum :: Ord a => Vector (n + 1) a -> a
#

O(n) Yield the maximum element of the non-empty vector.

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

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

valueminimum :: Ord a => Vector (n + 1) a -> a
#

O(n) Yield the minimum element of the non-empty vector.

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

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

valuemaxIndex :: Ord a => Vector (n + 1) a -> Finite (n + 1)
#

O(n) Yield the index of the maximum element of the non-empty vector.

valuemaxIndexBy :: (a -> a -> Ordering) -> 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.

valueminIndex :: Ord a => Vector (n + 1) a -> Finite (n + 1)
#

O(n) Yield the index of the minimum element of the non-empty vector.

valueminIndexBy :: (a -> a -> Ordering) -> 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.

Monadic folds

valuefoldM :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a
#

O(n) Monadic fold.

valueifoldM :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a
#

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

valuefold1M :: Monad m => (a -> a -> m a) -> Vector (1 + n) a -> m a
#

O(n) Monadic fold over non-empty vectors.

valuefoldM' :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m a
#

O(n) Monadic fold with strict accumulator.

valueifoldM' :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m a
#

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

valuefold1M' :: Monad m => (a -> a -> m a) -> Vector (n + 1) a -> m a
#

O(n) Monadic fold over non-empty vectors with strict accumulator.

valuefoldM_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m ()
#

O(n) Monadic fold that discards the result.

valueifoldM_ :: Monad m => (a -> Finite n -> b -> m a) -> a -> Vector n b -> m ()
#

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

valuefold1M_ :: Monad m => (a -> a -> m a) -> Vector (n + 1) a -> m ()
#

O(n) Monadic fold over non-empty vectors that discards the result.

valuefoldM'_ :: Monad m => (a -> b -> m a) -> a -> Vector n b -> m ()
#

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

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

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

valuefold1M'_ :: Monad m => (a -> a -> m a) -> Vector (n + 1) a -> m ()
#

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

Monadic sequencing

Prefix sums (scans)

16 declarations
valueprescanl :: (a -> b -> a) -> a -> Vector n b -> Vector n a
#

O(n) Prescan.

prescanl f z = init . scanl f z

Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6>

valuescanl :: (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a
#

O(n) Haskell-style scan.

valuescanl' :: (a -> b -> a) -> a -> Vector n b -> Vector (1 + n) a
#

O(n) Haskell-style scan with strict accumulator.

valuescanl1 :: (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a
#

O(n) Scan over a non-empty vector.

valuescanl1' :: (a -> a -> a) -> Vector (1 + n) a -> Vector (2 + n) a
#

O(n) Scan over a non-empty vector with a strict accumulator.

valueprescanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b
#

O(n) Right-to-left prescan with strict accumulator.

valuepostscanr' :: (a -> b -> b) -> b -> Vector n a -> Vector n b
#

O(n) Right-to-left scan with strict accumulator.

valuescanr :: (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b
#

O(n) Right-to-left Haskell-style scan.

valuescanr' :: (a -> b -> b) -> b -> Vector n a -> Vector (n + 1) b
#

O(n) Right-to-left Haskell-style scan with strict accumulator.

valuescanr1 :: (a -> a -> a) -> Vector (n + 1) a -> Vector (n + 2) a
#

O(n) Right-to-left scan over a non-empty vector.

valuescanr1' :: (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.

Conversions

0 declarations

Lists

valuetoList :: Vector n a -> [a]
#

O(n) Convert a vector to a list.

valuefromListN :: 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.

valuefromListN' :: KnownNat n => p 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.

valuewithSizedList
  1. :: [a]
  2. -> forall (n :: Nat). KnownNat n => Vector n a -> r
  3. -> 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

Mutable vectors

valueunsafeThaw :: PrimMonad m => Vector n a -> m (MVector n (PrimState m) a)
#

O(n) Unsafely convert an immutable vector to a mutable one without copying. The immutable vector may not be used after this operation.

Unsized Vectors

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

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.

valuewithVectorUnsafe :: (Vector a -> Vector b) -> Vector n a -> Vector 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.