0 | module Data.Vect.Properties.Fin
3 | import Data.Vect.Elem
4 | import Data.Vect.Extra
10 | data NonEmpty : Vect n a -> Type where
11 | IsNonEmpty : NonEmpty (x :: xs)
15 | etaCons : (xs : Vect (S n) a) -> head xs :: tail xs = xs
16 | etaCons (x :: xs) = Refl
20 | finNonZero : Fin n -> NonZero n
21 | finNonZero FZ = ItIsSucc
22 | finNonZero (FS i) = ItIsSucc
26 | finNonEmpty : (0 xs : Vect n a) -> NonZero n -> NonEmpty xs
27 | finNonEmpty xs ItIsSucc = replace {p = NonEmpty} (etaCons xs) IsNonEmpty
32 | finToElem : (0 xs : Vect n a) -> (i : Fin n) -> (index i xs) `Elem` xs
33 | finToElem {n } xs i with (finNonEmpty xs $
finNonZero i)
34 | finToElem {n = S n} (x :: xs) FZ | IsNonEmpty = Here
35 | finToElem {n = S n} (x :: xs) (FS i) | IsNonEmpty = There (finToElem xs i)
39 | indexNaturalityWithElem : (i : Fin n) -> (xs : Vect n a) -> (f : (x : a) -> (0 pos : x `Elem` xs) -> b)
40 | -> index i (mapWithElem xs f) = f (index i xs) (finToElem xs i)
41 | indexNaturalityWithElem {n } i xs f with (finNonEmpty xs (finNonZero i))
42 | indexNaturalityWithElem {n = _} FZ (x :: xs) f | IsNonEmpty = Refl
43 | indexNaturalityWithElem {n = _} (FS i) (x :: xs) f | IsNonEmpty = indexNaturalityWithElem i xs _