vector
本頁內容尚未翻譯。
data Vec (A : Type) : Nat -> TypeA list of exactly n elements of A.
Vec.head
Section titled “Vec.head”def head {A : Type} {n : Nat} (v : Vec A (succ n)) : AThe first element of a non-empty vector.
Vec.tail
Section titled “Vec.tail”def tail {A : Type} {n : Nat} (v : Vec A (succ n)) : Vec A nA non-empty vector without its first element.
Vec.toList
Section titled “Vec.toList”def toList {A : Type} {n : Nat} (v : Vec A n) : List AThe elements as a list, in order.
Vec.fromList
Section titled “Vec.fromList”def fromList {A : Type} (xs : List A) : Vec A (List.length xs)A list as a vector of its length.
Vec.map
Section titled “Vec.map”def map {A : Type} {B : Type} {n : Nat} (f : A -> B) (v : Vec A n) : Vec B nf applied to every element.
Vec.replicate
Section titled “Vec.replicate”def replicate {A : Type} (n : Nat) (x : A) : Vec A nn copies of x.
Vec.append
Section titled “Vec.append”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.
Vec.zipWith
Section titled “Vec.zipWith”def zipWith {A : Type} {B : Type} {C : Type} {n : Nat} (f : A -> B -> C) (a : Vec A n) (b : Vec B n) : Vec C nf applied to the elements at the same positions of two vectors of the same length.
Vec.foldRight
Section titled “Vec.foldRight”def foldRight {A : Type} {B : Type} {n : Nat} (f : A -> B -> B) (z : B) (v : Vec A n) : BThe elements folded from the last to the first: f x rest.
Vec.get
Section titled “Vec.get”def get {A : Type} {n : Nat} (v : Vec A n) (i : Fin n) : AThe element at an index (Fin n cannot be out of range: there is no index into vnil).
Vec.tabulate
Section titled “Vec.tabulate”def tabulate {A : Type} (n : Nat) (f : Fin n -> A) : Vec A nThe vector of f at every index, in order.
Vec.toListLength
Section titled “Vec.toListLength”def toListLength {A : Type} {n : Nat} (v : Vec A n) : List.length (toList v) = nThe list of a vector has the length the type gives.
Vec.mapToList
Section titled “Vec.mapToList”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.
Vec.appendToList
Section titled “Vec.appendToList”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.
Vec.fromListToList
Section titled “Vec.fromListToList”def fromListToList {A : Type} (xs : List A) : toList (fromList xs) = xsA list’s vector gives the list back.