1
module Prelude.Vec where
3
open import Prelude.Nat
4
open import Prelude.Fin
5
open import Prelude.Unit
6
open import Prelude.List using (List ; [] ; _::_)
9
data Vec (A : Set) : Nat -> Set where
10
_::_ : forall {n} -> A -> Vec A n -> Vec A (S n)
15
_++_ : {A : Set}{m n : Nat} -> Vec A m -> Vec A n -> Vec A (m + n)
17
(x :: xs) ++ ys = x :: (xs ++ ys)
19
snoc : {A : Set}{n : Nat} -> Vec A n -> A -> Vec A (S n)
21
snoc (x :: xs) e = x :: snoc xs e
23
length : {A : Set}{n : Nat} -> Vec A n -> Nat
25
length (x :: xs) = 1 + length xs
27
length' : {A : Set}{n : Nat} -> Vec A n -> Nat
30
zipWith3 : ∀ {A B C D n} -> (A -> B -> C -> D) -> Vec A n -> Vec B n -> Vec C n -> Vec D n
31
zipWith3 f [] [] [] = []
32
zipWith3 f (x :: xs) (y :: ys) (z :: zs) = f x y z :: zipWith3 f xs ys zs
34
zipWith : ∀ {A B C n} -> (A -> B -> C) -> Vec A n -> Vec B n -> {u : Unit} -> Vec C n
36
zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys {u = unit}
38
_!_ : ∀ {A n} -> Vec A n -> Fin n -> A
40
_ :: xs ! fs n = xs ! n
43
_[_]=_ : {A : Set}{n : Nat} -> Vec A n -> Fin n -> A -> Vec A n
44
(a :: as) [ fz ]= e = e :: as
45
(a :: as) [ fs n ]= e = a :: (as [ n ]= e)
48
map : ∀ {A B n}(f : A -> B)(xs : Vec A n) -> Vec B n
50
map f (x :: xs) = f x :: map f xs
52
forgetL : {A : Set}{n : Nat} -> Vec A n -> List A
54
forgetL (x :: xs) = x :: forgetL xs
56
rem : {A : Set}(xs : List A) -> Vec A (Prelude.List.length xs)
58
rem (x :: xs) = x :: rem xs
b'\\ No newline at end of file'