on master help sign in
Merge pull request #1272 from jeffersoncarpenter/vect-insertAt

added insertAt function to Vect

commit47bf9d782451254195d12298947035b2df869f07 authorEdwin Brady <edwin.brady@gmail.com> dateSun 1 Jun 2014, 16:18 (12 years ago) parent119956aacf32dd
1 file changed+6
libs/prelude/Prelude/Vect.idr+6
libs/prelude/Prelude/Vect.idr+6
@@ -68,6 +68,12 @@ index fZ (x::xs) = x
6868index (fS k) (x::xs) = index k xs
6969index fZ [] impossible
7070
71+||| Insert an element at a particular index
72+insertAt : Fin (S n) -> a -> Vect n a -> Vect (S n) a
73+insertAt fZ y xs = y :: xs
74+insertAt (fS k) y (x::xs) = x :: insertAt k y xs
75+insertAt (fS k) y [] = absurd k
76+
7177||| Construct a new vector consisting of all but the indicated element
7278deleteAt : Fin (S n) -> Vect (S n) a -> Vect n a
7379deleteAt fZ (x::xs) = xs