on master help sign in
added insertAt function to Vect
commite3e35287ba0f637a37daf80a116ffb962435bdf3 authorjeffersoncarpenter <jeffersoncarpenter2@gmail.com> dateThu 29 May 2014, 05:06 (12 years ago) parent43d33b3
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 [] = [y]
74+insertAt (fS k) y (x::xs) = x :: insertAt k y xs
75+insertAt k y xs = y :: xs
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