2 | import Data.Fin.Minus
4 | import Data.SortedMap
5 | import Data.SortedSet
11 | mapI : (f : Fin n -> a -> b) -> Vect n a -> Vect n b
13 | mapI f (x::xs) = f FZ x :: mapI (f . FS) xs
16 | toListI : Vect n a -> List (a, Fin n)
18 | toListI (x::xs) = (x, FZ) :: (map FS <$> toListI xs)
21 | withIndex : Vect n a -> Vect n (Fin n, a)
22 | withIndex = mapI (,)
25 | drop'' : (xs : Vect n a) -> (count : Fin $
S n) -> Vect (n - count) a
27 | drop'' (_::xs) (FS c) = drop'' xs c
30 | mapPre : ((i : Fin n) -> Vect (finToNat i) b -> a -> b) -> Vect n a -> Vect n b
32 | mapPre f (x::xs) = let y = f FZ [] x in y :: mapPre (\i, ys => f (FS i) (y::ys)) xs
35 | fromMap : {n : _} -> SortedMap (Fin n) a -> Vect n (Maybe a)
36 | fromMap = foldl (flip . uncurry $
\i => replaceAt i . Just) (replicate _ Nothing) . SortedMap.toList
39 | presenceVect : {n : _} -> SortedSet (Fin n) -> Vect n Bool
40 | presenceVect = tabulate . flip contains
43 | reverseMapping : Ord a => Vect n a -> SortedMap a $
List1 $
Fin n
44 | reverseMapping = concat . mapI (\idx, x => singleton x $
singleton idx)