vector-sized-0.2.0.0: Size tagged vectors

Safe HaskellNone
LanguageHaskell2010

Data.Vector.Storable.Sized

Contents

Synopsis

Documentation

Construction

fromVector :: forall a n. (KnownNat n, Storable a) => Vector a -> Maybe (Vector n a) #

Convert a Vector into a Vector if it has the correct size, otherwise return Nothing.

replicate :: forall a n. (Storable a, KnownNat n) => a -> Vector n a #

O(n) Construct a vector with the same element in each position.

singleton :: forall a. Storable a => a -> Vector 1 a #

O(1) construct a single element vector.

generate :: forall n a. (Storable a, KnownNat n) => Proxy n -> (Int -> a) -> Vector n a #

O(n) construct a vector of the given length by applying the function to each index.

Elimination

length :: forall a n. Storable a => Vector n a -> Int #

O(1) Get the length of the vector.

index :: forall m a n. (KnownNat n, KnownNat m, Storable a) => Vector (m + n) a -> Proxy n -> a #

O(1) Index safely into the vector using a type level index.

head :: forall a n. Storable a => Vector (n + 1) a -> a #

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

last :: forall a n. Storable a => Vector (n + 1) a -> a #

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

Extract subsets

tail :: forall a n. Storable a => Vector (n + 1) a -> Vector n a #

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

init :: forall a n. Storable a => Vector (n + 1) a -> Vector n a #

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

take :: forall m a n. (KnownNat n, KnownNat m, Storable a) => Proxy n -> Vector (m + n) a -> Vector n a #

O(1) Yield the first n elements. The resultant vector always contains this many elements.

drop :: forall m a n. (KnownNat n, KnownNat m, Storable a) => Proxy n -> Vector (m + n) a -> Vector m a #

O(1) Yield all but the first n elements.

Mapping

map :: forall a b n. (Storable a, Storable b) => (a -> b) -> Vector n a -> Vector n b #

O(n) Map a function over the vector.

Folding

foldl' :: forall a b n. Storable b => (a -> b -> a) -> a -> Vector n b -> a #

O(n) Left fold with a strict accumulator.

foldl1' :: forall a n. Storable a => (a -> a -> a) -> Vector (n + 1) a -> a #

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