跳到內容

vector

本頁內容尚未翻譯。

data Vec (A : Type) : Nat -> Type

A list of exactly n elements of A.

def head {A : Type} {n : Nat} (v : Vec A (succ n)) : A

The first element of a non-empty vector.

def tail {A : Type} {n : Nat} (v : Vec A (succ n)) : Vec A n

A non-empty vector without its first element.

def toList {A : Type} {n : Nat} (v : Vec A n) : List A

The elements as a list, in order.

def fromList {A : Type} (xs : List A) : Vec A (List.length xs)

A list as a vector of its length.

def map {A : Type} {B : Type} {n : Nat} (f : A -> B) (v : Vec A n) : Vec B n

f applied to every element.

def replicate {A : Type} (n : Nat) (x : A) : Vec A n

n copies of x.

def append {A : Type} {m : Nat} {n : Nat} (a : Vec A m) (b : Vec A n) : Vec A (add m n)

The elements of a, then those of b.

def zipWith {A : Type} {B : Type} {C : Type} {n : Nat} (f : A -> B -> C) (a : Vec A n) (b : Vec B n) : Vec C n

f applied to the elements at the same positions of two vectors of the same length.

def foldRight {A : Type} {B : Type} {n : Nat} (f : A -> B -> B) (z : B) (v : Vec A n) : B

The elements folded from the last to the first: f x rest.

def get {A : Type} {n : Nat} (v : Vec A n) (i : Fin n) : A

The element at an index (Fin n cannot be out of range: there is no index into vnil).

def tabulate {A : Type} (n : Nat) (f : Fin n -> A) : Vec A n

The vector of f at every index, in order.

def toListLength {A : Type} {n : Nat} (v : Vec A n) : List.length (toList v) = n

The list of a vector has the length the type gives.

def mapToList {A : Type} {B : Type} {n : Nat} (f : A -> B) (v : Vec A n) : toList (map f v) = List.map f (toList v)

Mapping a vector, then taking its list, is mapping its list.

def appendToList {A : Type} {m : Nat} {n : Nat} (a : Vec A m) (b : Vec A n) : toList (append a b) = List.append (toList a) (toList b)

The list of an appended vector is the appended lists.

def fromListToList {A : Type} (xs : List A) : toList (fromList xs) = xs

A list’s vector gives the list back.