Module

Data.Vec

#Vec

newtype Vec s a

Vec s a is an array with a fixed size s defined at the type level.

Instances

#empty

empty :: forall a. Vec D0 a

An empty vector.

#cons

cons :: forall s s' a. Succ s s' => a -> Vec s a -> Vec s' a

Prepend a value to the front of a vector, creating a vector of size Succ s.

#(+>)

Operator alias for Data.Vec.cons (right-associative / precedence 5)

#snoc

snoc :: forall s s' a. Succ s s' => a -> Vec s a -> Vec s' a

Append a value to the end of a vector, creating a vector of size Succ s.

#uncons

uncons :: forall s1 s2 a. Pred s1 s2 => Vec s1 a -> { head :: a, tail :: Vec s2 a }

Get the head and the tail of a non-empty vector.

#singleton

singleton :: forall a. a -> Vec D1 a

Construct a vector containing only a single element.

#vec2

vec2 :: forall a. a -> a -> Vec D2 a

shortcut for creating a 2d-Vec

#vec3

vec3 :: forall a. a -> a -> a -> Vec D3 a

shortcut for creating a 3d-Vec

#fill

fill :: forall a s. Nat s => (Int -> a) -> Vec s a

fill vec using a function which is given indices

#range

range :: forall n1 n2 n3 max min diff. Nat n1 => Nat n2 => Max n1 n2 max => Min n1 n2 min => Sub max min diff => Succ diff n3 => n1 -> n2 -> Vec n3 Int

#replicate

replicate :: forall s a. Nat s => s -> a -> Vec s a

Construct a vector of a given length containing the same element repeated.

#replicate'

replicate' :: forall s a. Nat s => a -> Vec s a

#fromArray

fromArray :: forall s a. Nat s => Array a -> Maybe (Vec s a)

Convert an array to a vector.

#length

length :: forall s a. Nat s => Vec s a -> Int

Get the length of a vector as an integer.

#lengthT

lengthT :: forall s a. Nat s => Vec s a -> s

Get the length of a vector as a type level number.

#toArray

toArray :: forall s a. Vec s a -> Array a

Convert a vector into an array. This simply unwraps the underlying array, so it has no runtime cost.

#toUnfoldable

toUnfoldable :: forall f s a. Unfoldable f => Nat s => Vec s a -> f a

Convert a vector into any Unfoldable.

#index

index :: forall i s a. Nat i => Lt i s => Vec s a -> i -> a

Get the element at a given index inside a vector. Index out of bounds errors are caught at compile time.

Example:

myVector = 1 +> 2 +> 3 +> 4 +> empty
value = index myVector d2
-- value == 3
value = index myVector d4
-- out of bounds so does not type check

#(!!)

Operator alias for Data.Vec.index (left-associative / precedence 8)

#index'

index' :: forall s a. Vec s a -> Int -> Maybe a

Value-level indexation with runtime bounds check.

#concat

concat :: forall s1 s2 s3 a. Add s1 s2 s3 => Vec s1 a -> Vec s2 a -> Vec s3 a

Concatenate two vectors together.

#updateAt

updateAt :: forall i s a. Nat i => Lt i s => i -> a -> Vec s a -> Vec s a

Update a vector with a given value inserted at a given index.

#modifyAt

modifyAt :: forall i s a. Nat i => Lt i s => i -> (a -> a) -> Vec s a -> Vec s a

Update a vector at a given index using a function.

#insertAt

insertAt :: forall i s1 s2 a. Nat i => Lt i s1 => Succ s1 s2 => i -> a -> Vec s1 a -> Vec s2 a

Insert a value at a given index inside a vector, returning a vector that is one element larger.

#deleteAt

deleteAt :: forall i s1 s2 a. Nat i => Lt i s1 => Pred s1 s2 => i -> Vec s1 a -> Vec s2 a

Remove an element at a given index inside a vector, returning a vector that is one element smaller.

#head

head :: forall s a. Pos s => Vec s a -> a

Get the head of a non-empty vector.

#last

last :: forall s a. Pos s => Vec s a -> a

Get the last element of a non-empty vector.

#tail

tail :: forall s1 s2 a. Pred s1 s2 => Vec s1 a -> Vec s2 a

Get the tail of a non-empty vector.

#init

init :: forall s1 s2 a. Pred s1 s2 => Vec s1 a -> Vec s2 a

Get all but the last element of a non-empty vector.

#insert

insert :: forall s1 s2 a. Succ s1 s2 => Ord a => a -> Vec s1 a -> Vec s2 a

Insert an element into a sorted vector.

#insertBy

insertBy :: forall s1 s2 a. Succ s1 s2 => (a -> a -> Ordering) -> a -> Vec s1 a -> Vec s2 a

Insert an element into a sorted vector using an ordering function.

#slice

slice :: forall i1 i2 s1 s2 a. Nat i1 => Nat i2 => LtEq i1 s1 => LtEq i2 s1 => LtEq i1 i2 => Sub i2 i1 s2 => i1 -> i2 -> Vec s1 a -> Vec s2 a

Get a sub-vector from index i1 up to but not including index i2.

#slice'

slice' :: forall i1 i2 s1 s2 a. Nat i1 => Nat i2 => LtEq i1 s1 => LtEq i2 s1 => LtEq i1 i2 => Sub i2 i1 s2 => i1 -> Vec s1 a -> Vec s2 a

#take

take :: forall c s a. Nat c => LtEq c s => c -> Vec s a -> Vec c a

Get the first c elements from a vector.

#take'

take' :: forall c s a. Nat c => LtEq c s => Vec s a -> Vec c a

#drop

drop :: forall c s1 s2 a. Nat c => LtEq c s1 => Sub s1 c s2 => c -> Vec s1 a -> Vec s2 a

Drop the first c elements from a vector.

#drop'

drop' :: forall c s1 s2 a. Nat c => LtEq c s1 => Sub s1 c s2 => Vec s1 a -> Vec s2 a

#zip

zip :: forall s1 s2 s3 a b. Min s1 s2 s3 => Vec s1 a -> Vec s2 b -> Vec s3 (Tuple a b)

Zip two vectors together into a vector of tuples.

The new vector will be the size of the smallest input vector, and superfluous elements from the other will be discarded.

#zipWith

zipWith :: forall s1 s2 s3 a b c. Min s1 s2 s3 => (a -> b -> c) -> Vec s1 a -> Vec s2 b -> Vec s3 c

Zip two vectors together using a combining function.

The new vector will be the size of the smallest input vector, and superfluous elements from the other will be discarded.

#zipWithE

zipWithE :: forall s a b c. (a -> b -> c) -> Vec s a -> Vec s b -> Vec s c

Zip two vectors with equal length together using a combining function.

#unzip

unzip :: forall s a b. Vec s (Tuple a b) -> Tuple (Vec s a) (Vec s b)

Unzip a vector of tuples into a tuple of vectors.

#sort

sort :: forall s a. Ord a => Vec s a -> Vec s a

Sort a vector of Ords.

#sortBy

sortBy :: forall s a. (a -> a -> Ordering) -> Vec s a -> Vec s a

Sort a vector using an ordering function.

#reverse

reverse :: forall s a. Vec s a -> Vec s a

Reverse a vector.

#dotProduct

dotProduct :: forall s a. Semiring a => Vec s a -> Vec s a -> a

Modules