@@ -1,11 +1,599 @@
11module Data.Vect
22
3+import public Data.Fin
34import Language.Reflection
4−import public Data.VectType
55
66%access public
77%default total
88
9+infixr 7 ::
10+
11+||| Vectors: Generic lists with explicit length in the type
12+%elim
13+data Vect : Nat -> Type -> Type where
14+ ||| Empty vector
15+ Nil : Vect Z a
16+ ||| A non-empty vector of length `S k`, consisting of a head element and
17+ ||| the rest of the list, of length `k`.
18+ (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a
19+
20+-- Hints for interactive editing
21+%name Vect xs,ys,zs,ws
22+
23+--------------------------------------------------------------------------------
24+-- Length
25+--------------------------------------------------------------------------------
26+
27+||| Calculate the length of a `Vect`.
28+|||
29+||| **Note**: this is only useful if you don't already statically know the length
30+||| and you want to avoid matching the implicit argument for erasure reasons.
31+||| @ n the length (provably equal to the return value)
32+||| @ xs the vector
33+length : (xs : Vect n a) -> Nat
34+length [] = 0
35+length (x::xs) = 1 + length xs
36+
37+||| Show that the length function on vectors in fact calculates the length
38+private lengthCorrect : (n : Nat) -> (xs : Vect n a) -> length xs = n
39+lengthCorrect Z [] = Refl
40+lengthCorrect (S n) (x :: xs) = rewrite lengthCorrect n xs in Refl
41+
42+--------------------------------------------------------------------------------
43+-- Indexing into vectors
44+--------------------------------------------------------------------------------
45+
46+||| All but the first element of the vector
47+tail : Vect (S n) a -> Vect n a
48+tail (x::xs) = xs
49+
50+||| Only the first element of the vector
51+head : Vect (S n) a -> a
52+head (x::xs) = x
53+
54+||| The last element of the vector
55+last : Vect (S n) a -> a
56+last (x::[]) = x
57+last (x::y::ys) = last $ y::ys
58+
59+||| All but the last element of the vector
60+init : Vect (S n) a -> Vect n a
61+init (x::[]) = []
62+init (x::y::ys) = x :: init (y::ys)
63+
64+||| Extract a particular element from a vector
65+index : Fin n -> Vect n a -> a
66+index FZ (x::xs) = x
67+index (FS k) (x::xs) = index k xs
68+
69+
70+||| Insert an element at a particular index
71+insertAt : Fin (S n) -> a -> Vect n a -> Vect (S n) a
72+insertAt FZ y xs = y :: xs
73+insertAt (FS k) y (x::xs) = x :: insertAt k y xs
74+insertAt (FS k) y [] = absurd k
75+
76+||| Construct a new vector consisting of all but the indicated element
77+deleteAt : Fin (S n) -> Vect (S n) a -> Vect n a
78+deleteAt FZ (x::xs) = xs
79+deleteAt {n = S m} (FS k) (x::xs) = x :: deleteAt k xs
80+deleteAt {n = Z} (FS k) (x::xs) = absurd k
81+deleteAt _ [] impossible
82+
83+||| Replace an element at a particlar index with another
84+replaceAt : Fin n -> t -> Vect n t -> Vect n t
85+replaceAt FZ y (x::xs) = y :: xs
86+replaceAt (FS k) y (x::xs) = x :: replaceAt k y xs
87+
88+||| Replace the element at a particular index with the result of applying a function to it
89+||| @ i the index to replace at
90+||| @ f the update function
91+||| @ xs the vector to replace in
92+updateAt : (i : Fin n) -> (f : t -> t) -> (xs : Vect n t) -> Vect n t
93+updateAt FZ f (x::xs) = f x :: xs
94+updateAt (FS k) f (x::xs) = x :: updateAt k f xs
95+
96+--------------------------------------------------------------------------------
97+-- Subvectors
98+--------------------------------------------------------------------------------
99+
100+||| Get the first n elements of a Vect
101+||| @ n the number of elements to take
102+take : (n : Nat) -> Vect (n + m) a -> Vect n a
103+take Z xs = []
104+take (S k) (x :: xs) = x :: take k xs
105+
106+||| Remove the first n elements of a Vect
107+||| @ n the number of elements to remove
108+drop : (n : Nat) -> Vect (n + m) a -> Vect m a
109+drop Z xs = xs
110+drop (S k) (x :: xs) = drop k xs
111+
112+||| Take the longest prefix of a Vect such that all elements satisfy some
113+||| Boolean predicate.
114+|||
115+||| @ p the predicate
116+takeWhile : (p : a -> Bool) -> Vect n a -> (q ** Vect q a)
117+takeWhile p [] = (_ ** [])
118+takeWhile p (x::xs) =
119+ let (len ** ys) = takeWhile p xs
120+ in if p x then
121+ (S len ** x :: ys)
122+ else
123+ (_ ** [])
124+
125+||| Remove the longest prefix of a Vect such that all removed elements satisfy some
126+||| Boolean predicate.
127+|||
128+||| @ p the predicate
129+dropWhile : (p : a -> Bool) -> Vect n a -> (q ** Vect q a)
130+dropWhile p [] = (_ ** [])
131+dropWhile p (x::xs) =
132+ if p x then
133+ dropWhile p xs
134+ else
135+ (_ ** x::xs)
136+
137+--------------------------------------------------------------------------------
138+-- Transformations
139+--------------------------------------------------------------------------------
140+
141+||| Reverse the order of the elements of a vector
142+reverse : Vect n a -> Vect n a
143+reverse xs = go [] xs
144+ where go : Vect n a -> Vect m a -> Vect (n+m) a
145+ go {n} acc [] = rewrite plusZeroRightNeutral n in acc
146+ go {n} {m=S m} acc (x :: xs) = rewrite sym $ plusSuccRightSucc n m
147+ in go (x::acc) xs
148+
149+||| Alternate an element between the other elements of a vector
150+||| @ sep the element to intersperse
151+||| @ xs the vector to separate with `sep`
152+intersperse : (sep : a) -> (xs : Vect n a) -> Vect (n + pred n) a
153+intersperse sep [] = []
154+intersperse sep (x::xs) = x :: intersperse' sep xs
155+ where
156+ intersperse' : a -> Vect n a -> Vect (n + n) a
157+ intersperse' sep [] = []
158+ intersperse' {n=S n} sep (x::xs) = rewrite sym $ plusSuccRightSucc n n
159+ in sep :: x :: intersperse' sep xs
160+
161+--------------------------------------------------------------------------------
162+-- Conversion from list (toList is provided by Foldable)
163+--------------------------------------------------------------------------------
164+
165+
166+fromList' : Vect n a -> (l : List a) -> Vect (length l + n) a
167+fromList' ys [] = ys
168+fromList' {n} ys (x::xs) =
169+ rewrite (plusSuccRightSucc (length xs) n) ==>
170+ Vect (plus (length xs) (S n)) a in
171+ fromList' (x::ys) xs
172+
173+||| Convert a list to a vector.
174+|||
175+||| The length of the list should be statically known.
176+fromList : (l : List a) -> Vect (length l) a
177+fromList l =
178+ rewrite (sym $ plusZeroRightNeutral (length l)) in
179+ reverse $ fromList' [] l
180+
181+--------------------------------------------------------------------------------
182+-- Building (bigger) vectors
183+--------------------------------------------------------------------------------
184+
185+||| Append two vectors
186+(++) : Vect m a -> Vect n a -> Vect (m + n) a
187+(++) [] ys = ys
188+(++) (x::xs) ys = x :: xs ++ ys
189+
190+||| Repeate some value n times
191+||| @ n the number of times to repeat it
192+||| @ x the value to repeat
193+replicate : (n : Nat) -> (x : a) -> Vect n a
194+replicate Z x = []
195+replicate (S k) x = x :: replicate k x
196+
197+--------------------------------------------------------------------------------
198+-- Zips and unzips
199+--------------------------------------------------------------------------------
200+
201+||| Combine two equal-length vectors pairwise with some function
202+zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c
203+zipWith f [] [] = []
204+zipWith f (x::xs) (y::ys) = f x y :: zipWith f xs ys
205+
206+||| Combine three equal-length vectors into a vector with some function
207+zipWith3 : (a -> b -> c -> d) -> Vect n a -> Vect n b -> Vect n c -> Vect n d
208+zipWith3 f [] [] [] = []
209+zipWith3 f (x::xs) (y::ys) (z::zs) = f x y z :: zipWith3 f xs ys zs
210+
211+||| Combine two equal-length vectors pairwise
212+zip : Vect n a -> Vect n b -> Vect n (a, b)
213+zip = zipWith (\x,y => (x,y))
214+
215+||| Combine three equal-length vectors elementwise into a vector of tuples
216+zip3 : Vect n a -> Vect n b -> Vect n c -> Vect n (a, b, c)
217+zip3 = zipWith3 (\x,y,z => (x,y,z))
218+
219+||| Convert a vector of pairs to a pair of vectors
220+unzip : Vect n (a, b) -> (Vect n a, Vect n b)
221+unzip [] = ([], [])
222+unzip ((l, r)::xs) with (unzip xs)
223+ | (lefts, rights) = (l::lefts, r::rights)
224+
225+||| Convert a vector of three-tuples to a triplet of vectors
226+unzip3 : Vect n (a, b, c) -> (Vect n a, Vect n b, Vect n c)
227+unzip3 [] = ([], [], [])
228+unzip3 ((l,c,r)::xs) with (unzip3 xs)
229+ | (lefts, centers, rights) = (l::lefts, c::centers, r::rights)
230+
231+--------------------------------------------------------------------------------
232+-- Equality
233+--------------------------------------------------------------------------------
234+
235+instance (Eq a) => Eq (Vect n a) where
236+ (==) [] [] = True
237+ (==) (x::xs) (y::ys) =
238+ if x == y then
239+ xs == ys
240+ else
241+ False
242+
243+
244+--------------------------------------------------------------------------------
245+-- Order
246+--------------------------------------------------------------------------------
247+
248+instance Ord a => Ord (Vect n a) where
249+ compare [] [] = EQ
250+ compare (x::xs) (y::ys) =
251+ if x /= y then
252+ compare x y
253+ else
254+ compare xs ys
255+
256+
257+--------------------------------------------------------------------------------
258+-- Maps
259+--------------------------------------------------------------------------------
260+
261+instance Functor (Vect n) where
262+ map f [] = []
263+ map f (x::xs) = f x :: map f xs
264+
265+
266+||| Map a partial function across a vector, returning those elements for which
267+||| the function had a value.
268+|||
269+||| The first projection of the resulting pair (ie the length) will always be
270+||| at most the length of the input vector. This is not, however, guaranteed
271+||| by the type.
272+|||
273+||| @ f the partial function (expressed by returning `Maybe`)
274+||| @ xs the vector to check for results
275+mapMaybe : (f : a -> Maybe b) -> (xs : Vect n a) -> (m : Nat ** Vect m b)
276+mapMaybe f [] = (_ ** [])
277+mapMaybe f (x::xs) =
278+ let (len ** ys) = mapMaybe f xs
279+ in case f x of
280+ Just y => (S len ** y :: ys)
281+ Nothing => ( len ** ys)
282+
283+
284+--------------------------------------------------------------------------------
285+-- Folds
286+--------------------------------------------------------------------------------
287+
288+total foldrImpl : (t -> acc -> acc) -> acc -> (acc -> acc) -> Vect n t -> acc
289+foldrImpl f e go [] = go e
290+foldrImpl f e go (x::xs) = foldrImpl f e (go . (f x)) xs
291+
292+instance Foldable (Vect n) where
293+ foldr f e xs = foldrImpl f e id xs
294+
295+--------------------------------------------------------------------------------
296+-- Special folds
297+--------------------------------------------------------------------------------
298+
299+||| Flatten a vector of equal-length vectors
300+concat : Vect m (Vect n a) -> Vect (m * n) a
301+concat [] = []
302+concat (v::vs) = v ++ concat vs
303+
304+||| Foldr without seeding the accumulator
305+foldr1 : (t -> t -> t) -> Vect (S n) t -> t
306+foldr1 f (x::xs) = foldr f x xs
307+
308+||| Foldl without seeding the accumulator
309+foldl1 : (t -> t -> t) -> Vect (S n) t -> t
310+foldl1 f (x::xs) = foldl f x xs
311+--------------------------------------------------------------------------------
312+-- Scans
313+--------------------------------------------------------------------------------
314+
315+scanl : (b -> a -> b) -> b -> Vect n a -> Vect (S n) b
316+scanl f q [] = [q]
317+scanl f q (x::xs) = q :: scanl f (f q x) xs
318+
319+--------------------------------------------------------------------------------
320+-- Membership tests
321+--------------------------------------------------------------------------------
322+
323+||| Search for an item using a user-provided test
324+||| @ p the equality test
325+||| @ e the item to search for
326+||| @ xs the vector to search in
327+elemBy : (p : a -> a -> Bool) -> (e : a) -> (xs : Vect n a) -> Bool
328+elemBy p e [] = False
329+elemBy p e (x::xs) with (p e x)
330+ | True = True
331+ | False = elemBy p e xs
332+
333+||| Use the default Boolean equality on elements to search for an item
334+||| @ x what to search for
335+||| @ xs where to search
336+elem : Eq a => (x : a) -> (xs : Vect n a) -> Bool
337+elem = elemBy (==)
338+
339+||| Find the association of some key with a user-provided comparison
340+||| @ p the comparison operator for keys (True if they match)
341+||| @ e the key to look for
342+lookupBy : (p : a -> a -> Bool) -> (e : a) -> (xs : Vect n (a, b)) -> Maybe b
343+lookupBy p e [] = Nothing
344+lookupBy p e ((l, r)::xs) with (p e l)
345+ | True = Just r
346+ | False = lookupBy p e xs
347+
348+||| Find the assocation of some key using the default Boolean equality test
349+lookup : Eq a => a -> Vect n (a, b) -> Maybe b
350+lookup = lookupBy (==)
351+
352+||| Check if any element of xs is found in elems by a user-provided comparison
353+||| @ p the comparison operator
354+||| @ elems the vector to search
355+||| @ xs what to search for
356+hasAnyBy : (p : a -> a -> Bool) -> (elems : Vect m a) -> (xs : Vect n a) -> Bool
357+hasAnyBy p elems [] = False
358+hasAnyBy p elems (x::xs) with (elemBy p x elems)
359+ | True = True
360+ | False = hasAnyBy p elems xs
361+
362+||| Check if any element of xs is found in elems using the default Boolean equality test
363+hasAny : Eq a => Vect m a -> Vect n a -> Bool
364+hasAny = hasAnyBy (==)
365+
366+--------------------------------------------------------------------------------
367+-- Searching with a predicate
368+--------------------------------------------------------------------------------
369+
370+||| Find the first element of the vector that satisfies some test
371+||| @ p the test to satisfy
372+find : (p : a -> Bool) -> (xs : Vect n a) -> Maybe a
373+find p [] = Nothing
374+find p (x::xs) with (p x)
375+ | True = Just x
376+ | False = find p xs
377+
378+||| Find the index of the first element of the vector that satisfies some test
379+findIndex : (a -> Bool) -> Vect n a -> Maybe (Fin n)
380+findIndex p [] = Nothing
381+findIndex p (x :: xs) with (p x)
382+ | True = Just 0
383+ | False = map FS (findIndex p xs)
384+
385+||| Find the indices of all elements that satisfy some test
386+total findIndices : (a -> Bool) -> Vect m a -> (p ** Vect p Nat)
387+findIndices = findIndices' 0
388+ where
389+ total findIndices' : Nat -> (a -> Bool) -> Vect m a -> (p ** Vect p Nat)
390+ findIndices' cnt p [] = (_ ** [])
391+ findIndices' cnt p (x::xs) with (findIndices' (S cnt) p xs)
392+ | (_ ** tail) =
393+ if p x then
394+ (_ ** cnt::tail)
395+ else
396+ (_ ** tail)
397+
398+elemIndexBy : (a -> a -> Bool) -> a -> Vect m a -> Maybe (Fin m)
399+elemIndexBy p e = findIndex $ p e
400+
401+elemIndex : Eq a => a -> Vect m a -> Maybe (Fin m)
402+elemIndex = elemIndexBy (==)
403+
404+total elemIndicesBy : (a -> a -> Bool) -> a -> Vect m a -> (p ** Vect p Nat)
405+elemIndicesBy p e = findIndices $ p e
406+
407+total elemIndices : Eq a => a -> Vect m a -> (p ** Vect p Nat)
408+elemIndices = elemIndicesBy (==)
409+
410+--------------------------------------------------------------------------------
411+-- Filters
412+--------------------------------------------------------------------------------
413+
414+||| Find all elements of a vector that satisfy some test
415+total filter : (a -> Bool) -> Vect n a -> (p ** Vect p a)
416+filter p [] = ( _ ** [] )
417+filter p (x::xs) with (filter p xs)
418+ | (_ ** tail) =
419+ if p x then
420+ (_ ** x::tail)
421+ else
422+ (_ ** tail)
423+
424+||| Make the elements of some vector unique by some test
425+nubBy : (a -> a -> Bool) -> Vect n a -> (p ** Vect p a)
426+nubBy = nubBy' []
427+ where
428+ nubBy' : Vect m a -> (a -> a -> Bool) -> Vect n a -> (p ** Vect p a)
429+ nubBy' acc p [] = (_ ** [])
430+ nubBy' acc p (x::xs) with (elemBy p x acc)
431+ | True = nubBy' acc p xs
432+ | False with (nubBy' (x::acc) p xs)
433+ | (_ ** tail) = (_ ** x::tail)
434+
435+||| Make the elements of some vector unique by the default Boolean equality
436+nub : Eq a => Vect n a -> (p ** Vect p a)
437+nub = nubBy (==)
438+
439+deleteBy : (a -> a -> Bool) -> a -> Vect n a -> (p ** Vect p a)
440+deleteBy _ _ [] = (_ ** [])
441+deleteBy eq x (y::ys) =
442+ let (len ** zs) = deleteBy eq x ys
443+ in if x `eq` y then (_ ** ys) else (S len ** y ::zs)
444+
445+delete : (Eq a) => a -> Vect n a -> (p ** Vect p a)
446+delete = deleteBy (==)
447+
448+--------------------------------------------------------------------------------
449+-- Splitting and breaking lists
450+--------------------------------------------------------------------------------
451+
452+||| A tuple where the first element is a Vect of the n first elements and
453+||| the second element is a Vect of the remaining elements of the original Vect
454+||| It is equivalent to (take n xs, drop n xs)
455+||| @ n the index to split at
456+||| @ xs the Vect to split in two
457+splitAt : (n : Nat) -> (xs : Vect (n + m) a) -> (Vect n a, Vect m a)
458+splitAt n xs = (take n xs, drop n xs)
459+
460+partition : (a -> Bool) -> Vect n a -> ((p ** Vect p a), (q ** Vect q a))
461+partition p [] = ((_ ** []), (_ ** []))
462+partition p (x::xs) =
463+ let ((leftLen ** lefts), (rightLen ** rights)) = partition p xs in
464+ if p x then
465+ ((S leftLen ** x::lefts), (rightLen ** rights))
466+ else
467+ ((leftLen ** lefts), (S rightLen ** x::rights))
468+
469+--------------------------------------------------------------------------------
470+-- Predicates
471+--------------------------------------------------------------------------------
472+
473+isPrefixOfBy : (a -> a -> Bool) -> Vect m a -> Vect n a -> Bool
474+isPrefixOfBy p [] right = True
475+isPrefixOfBy p left [] = False
476+isPrefixOfBy p (x::xs) (y::ys) with (p x y)
477+ | True = isPrefixOfBy p xs ys
478+ | False = False
479+
480+isPrefixOf : Eq a => Vect m a -> Vect n a -> Bool
481+isPrefixOf = isPrefixOfBy (==)
482+
483+isSuffixOfBy : (a -> a -> Bool) -> Vect m a -> Vect n a -> Bool
484+isSuffixOfBy p left right = isPrefixOfBy p (reverse left) (reverse right)
485+
486+isSuffixOf : Eq a => Vect m a -> Vect n a -> Bool
487+isSuffixOf = isSuffixOfBy (==)
488+
489+--------------------------------------------------------------------------------
490+-- Conversions
491+--------------------------------------------------------------------------------
492+
493+total maybeToVect : Maybe a -> (p ** Vect p a)
494+maybeToVect Nothing = (_ ** [])
495+maybeToVect (Just j) = (_ ** [j])
496+
497+total vectToMaybe : Vect n a -> Maybe a
498+vectToMaybe [] = Nothing
499+vectToMaybe (x::xs) = Just x
500+
501+--------------------------------------------------------------------------------
502+-- Misc
503+--------------------------------------------------------------------------------
504+
505+catMaybes : Vect n (Maybe a) -> (p ** Vect p a)
506+catMaybes [] = (_ ** [])
507+catMaybes (Nothing::xs) = catMaybes xs
508+catMaybes ((Just j)::xs) with (catMaybes xs)
509+ | (_ ** tail) = (_ ** j::tail)
510+
511+diag : Vect n (Vect n a) -> Vect n a
512+diag [] = []
513+diag ((x::xs)::xss) = x :: diag (map tail xss)
514+
515+range : Vect n (Fin n)
516+range {n=Z} = []
517+range {n=S _} = FZ :: map FS range
518+
519+||| Transpose a Vect of Vects, turning rows into columns and vice versa.
520+|||
521+||| As the types ensure rectangularity, this is an involution, unlike `Prelude.List.transpose`.
522+transpose : Vect m (Vect n a) -> Vect n (Vect m a)
523+transpose [] = replicate _ []
524+transpose (x :: xs) = zipWith (::) x (transpose xs)
525+
526+--------------------------------------------------------------------------------
527+-- Applicative/Monad/Traversable
528+--------------------------------------------------------------------------------
529+
530+instance Applicative (Vect k) where
531+ pure = replicate _
532+
533+ fs <*> vs = zipWith apply fs vs
534+
535+||| This monad is different from the List monad, (>>=)
536+||| uses the diagonal.
537+instance Monad (Vect n) where
538+ m >>= f = diag (map f m)
539+
540+instance Traversable (Vect n) where
541+ traverse f [] = pure Vect.Nil
542+ traverse f (x::xs) = [| Vect.(::) (f x) (traverse f xs) |]
543+
544+--------------------------------------------------------------------------------
545+-- Show
546+--------------------------------------------------------------------------------
547+
548+instance Show a => Show (Vect n a) where
549+ show = show . toList
550+
551+--------------------------------------------------------------------------------
552+-- Properties
553+--------------------------------------------------------------------------------
554+
555+vectConsCong : (x : a) -> (xs : Vect n a) -> (ys : Vect m a) -> (xs = ys) -> (x :: xs = x :: ys)
556+vectConsCong x xs xs Refl = Refl
557+
558+vectNilRightNeutral : (xs : Vect n a) -> xs ++ [] = xs
559+vectNilRightNeutral [] = Refl
560+vectNilRightNeutral (x :: xs) =
561+ vectConsCong _ _ _ (vectNilRightNeutral xs)
562+
563+vectAppendAssociative : (x : Vect xLen a) -> (y : Vect yLen a) -> (z : Vect zLen a) -> x ++ (y ++ z) = (x ++ y) ++ z
564+vectAppendAssociative [] y z = Refl
565+vectAppendAssociative (x :: xs) ys zs =
566+ vectConsCong _ _ _ (vectAppendAssociative xs ys zs)
567+
568+--------------------------------------------------------------------------------
569+-- DecEq
570+--------------------------------------------------------------------------------
571+
572+total
573+vectInjective1 : {xs, ys : Vect n a} -> {x, y : a} -> x :: xs = y :: ys -> x = y
574+vectInjective1 {x=x} {y=x} {xs=xs} {ys=xs} Refl = Refl
575+
576+total
577+vectInjective2 : {xs, ys : Vect n a} -> {x, y : a} -> x :: xs = y :: ys -> xs = ys
578+vectInjective2 {x=x} {y=x} {xs=xs} {ys=xs} Refl = Refl
579+
580+instance DecEq a => DecEq (Vect n a) where
581+ decEq [] [] = Yes Refl
582+ decEq (x :: xs) (y :: ys) with (decEq x y)
583+ decEq (x :: xs) (x :: ys) | Yes Refl with (decEq xs ys)
584+ decEq (x :: xs) (x :: xs) | Yes Refl | Yes Refl = Yes Refl
585+ decEq (x :: xs) (x :: ys) | Yes Refl | No neq = No (neq . vectInjective2)
586+ decEq (x :: xs) (y :: ys) | No neq = No (neq . vectInjective1)
587+
588+{- The following definition is elaborated in a wrong case-tree. Examination pending.
589+instance DecEq a => DecEq (Vect n a) where
590+ decEq [] [] = Yes Refl
591+ decEq (x :: xs) (y :: ys) with (decEq x y, decEq xs ys)
592+ decEq (x :: xs) (x :: xs) | (Yes Refl, Yes Refl) = Yes Refl
593+ decEq (x :: xs) (y :: ys) | (_, No nEqTl) = No (\p => nEqTl (vectInjective2 p))
594+ decEq (x :: xs) (y :: ys) | (No nEqHd, _) = No (\p => nEqHd (vectInjective1 p))
595+-}
596+
9597--------------------------------------------------------------------------------
10598-- Elem
11599--------------------------------------------------------------------------------