{- Definition of vectors. Inspired by the Agda Standard Library -}

{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Vec.Base where

open import Cubical.Foundations.Prelude

open import Cubical.Data.Nat

private
  variable
     ℓ' : Level

    A : Type 

infixr 5 _∷_

data Vec (A : Type ) :   Type  where
  []  : Vec A zero
  _∷_ :  {n} (x : A) (xs : Vec A n)  Vec A (suc n)


-- Basic functions

length :  {n}  Vec A n  
length {n = n} _ = n

head :  {n}  Vec A (1 + n)  A
head (x  xs) = x

tail :  {n}  Vec A (1 + n)  Vec A n
tail (x  xs) = xs

map :  {A : Type } {B : Type ℓ'} {n}  (A  B)  Vec A n  Vec B n
map f []       = []
map f (x  xs) = f x  map f xs


-- Concatenation

infixr 5 _++_

_++_ :  {m n}  Vec A m  Vec A n  Vec A (m + n)
[]       ++ ys = ys
(x  xs) ++ ys = x  (xs ++ ys)

concat :  {m n}  Vec (Vec A m) n  Vec A (n * m)
concat []         = []
concat (xs  xss) = xs ++ concat xss