HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelinear-base-0.4.0Haskell2010

Data.Vector.Mutable.Linear

Mutable vectors with a linear API.

Vectors are arrays that grow automatically, that you can append to with push. They never shrink automatically to reduce unnecessary copying, use shrinkToFit to get rid of the wasted space.

To use mutable vectors, create a linear computation of type Vector a %1-> Ur b and feed it to constant or fromList.

Example

Example4 expressions
:set -XLinearTypesimport Prelude.Linearimport qualified Data.Vector.Mutable.Linear as Vector:{ isFirstZero :: Vector.Vector Int %1-> Ur Bool isFirstZero vec =   Vector.get 0 vec     & \(Ur ret, vec) -> vec `lseq` Ur (ret == 0):}
Example2 expressions
unur $ Vector.fromList [0..10] isFirstZeroTrueunur $ Vector.fromList [1,2,3] isFirstZeroFalse
  • 1 type
  • 23 values

A mutable vector

1 declaration
datadata Vector a where
#

A dynamic mutable vector.

Instances5Functor, Consumable, Dupable, Semigroup
  • Functor VectorDefined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal
  • Semigroup (Vector a)Defined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal
  • Consumable (Vector a)Defined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal
  • Dupable (Vector a)Defined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal
  • Semigroup (Vector a)Defined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal

Run a computation with a vector

3 declarations

Mutators

10 declarations
valueset :: HasCallStack => Int -> a -> Vector a %1 -> Vector a
#

Write to an element . Note: this will not write to elements beyond the current size of the vector and will error instead.

valuemodify
  1. :: HasCallStack
  2. => a -> (a, b)
  3. -> Int
  4. -> Vector a
  5. -> (Ur b, Vector a)
#

Modify a value inside a vector, with an ability to return an extra information. Errors if the index is out of bounds.

valuepush :: a -> Vector a %1 -> Vector a
#

Insert at the end of the vector. This will grow the vector if there is no empty space.

valueslice :: Int -> Int -> Vector a %1 -> Vector a
#

Return a slice of the vector with given size, starting from an offset.

Start offset + target size should be within the input vector, and both should be non-negative.

This is a constant time operation if the start offset is 0. Use shrinkToFit to remove the possible wasted space if necessary.

valueshrinkToFit :: Vector a %1 -> Vector a
#

Resize the vector to not have any wasted memory (size == capacity). This returns a semantically identical vector.

Accessors

6 declarations
valueget :: HasCallStack => Int -> Vector a %1 -> (Ur a, Vector a)
#

Read from a vector, with an in-range index and error for an index that is out of range (with the usual range 0..size-1).

valuesize :: Vector a %1 -> (Ur Int, Vector a)
#

Number of elements inside the vector.

This might be different than how much actual memory the vector is using. For that, see: capacity.

valuecapacity :: Vector a %1 -> (Ur Int, Vector a)
#

Capacity of a vector. In other words, the number of elements the vector can contain before it is copied to a bigger array.

valuetoList :: Vector a %1 -> Ur [a]
#

Return the vector elements as a lazy list.

Mutable-style interface

4 declarations