@@ -29,7 +29,7 @@ splitPair {n} {m} = MkIso (splitAt n) (uncurry (++)) toFrom fromTo
29 where pairify : q = w -> e = r -> (q, e) = (w, r)
29 where pairify : q = w -> e = r -> (q, e) = (w, r)
30 pairify Refl Refl = Refl
30 pairify Refl Refl = Refl
31 toFrom (ns, ms) = trans (splitAtTakeDrop n (ns ++ ms)) $ pairify (takePrefix ns ms) (dropPrefix ns ms)
31 toFrom (ns, ms) = trans (splitAtTakeDrop n (ns ++ ms)) $ pairify (takePrefix ns ms) (dropPrefix ns ms)
32− fromTo xs = rewrite splitAtTakeDrop {m=m} n xs in takeDropConcat n xs
32+ fromTo xs = rewrite splitAtTakeDrop {m} n xs in takeDropConcat n xs
34||| An `Iso` based on `zip` and `unzip`.
34||| An `Iso` based on `zip` and `unzip`.
35zipped : Iso (Vect n a, Vect n b) (Vect n (a, b))
35zipped : Iso (Vect n a, Vect n b) (Vect n (a, b))
@@ -68,7 +68,8 @@ transposition {a} = MkIso transpose transpose prf prf
68||| This is the inverse of `concat`.
68||| This is the inverse of `concat`.
69unconcat : Vect (n * m) a -> Vect n (Vect m a)
69unconcat : Vect (n * m) a -> Vect n (Vect m a)
70unconcat {n = Z} [] = []
70unconcat {n = Z} [] = []
71+unconcat {n = S k} {m} xs with (splitAt m xs)
71−unconcat {n = S k} {m} xs = let (xs', xss) = splitAt m xs in xs' :: unconcat xss
72+ | (xs', xss) = xs' :: unconcat xss
72||| An `Iso` based on `unconcat` and `concat`.
73||| An `Iso` based on `unconcat` and `concat`.
74||| ```idris example
75||| ```idris example
@@ -76,21 +77,17 @@ unconcat {n = S k} {m} xs = let (xs', xss) = splitAt m xs in xs' :: unconcat xss
77rectangular : Iso (Vect (n * m) a) (Vect n (Vect m a))
78rectangular : Iso (Vect (n * m) a) (Vect n (Vect m a))
78rectangular = MkIso unconcat concat toFrom fromTo
79rectangular = MkIso unconcat concat toFrom fromTo
79−-- TODO: Clean up after #4001 is fixed
80 where toFrom : (xss : Vect i (Vect o a)) -> unconcat (concat xss) = xss
80 where toFrom : (xss : Vect i (Vect o a)) -> unconcat (concat xss) = xss
81 toFrom {i = Z} [] = Refl
81 toFrom {i = Z} [] = Refl
82− toFrom {i = S k} {o} (xs :: xss) with (splitAt o (xs ++ concat xss)) proof p
83− | (tk, dr) = let sATK = sym $ trans p $ splitAtTakeDrop o (xs ++ concat xss)
82+ toFrom {i = S i} {o} (xs :: xss) = rewrite splitAtTakeDrop o {m = i * o} (xs ++ concat xss) in
84− tkp = trans (sym $ takePrefix xs $ concat xss) $ cong {f=fst} sATK
83+ rewrite takePrefix xs (concat xss) in
85− drp = trans (sym $ toFrom xss) $ cong {f=unconcat} $ trans (sym $ dropPrefix xs $ concat xss) $ cong {f=snd} sATK
84+ rewrite dropPrefix xs (concat xss) in
86− in replace {P = \dr' => tk :: dr' = xs :: xss} drp $ replace {P = \tk' => tk' :: xss = xs :: xss} tkp Refl
85+ cong (toFrom xss)
87 fromTo : (xs : Vect (i * o) a) -> concat (unconcat xs) = xs
86 fromTo : (xs : Vect (i * o) a) -> concat (unconcat xs) = xs
88 fromTo {i = Z} [] = Refl
87 fromTo {i = Z} [] = Refl
89− fromTo {i = S k} {o} xs with (splitAt o xs) proof p
90− | (tk, dr) = let sATK = sym $ trans p $ splitAtTakeDrop o xs
88+ fromTo {i = S i} {o} xs = rewrite splitAtTakeDrop o {m = i * o} xs in
91− tkp = cong {f=fst} sATK
89+ rewrite fromTo {i} {o} (drop o xs) in
92− drp = trans (cong {f=snd} sATK) $ sym $ fromTo dr
93− in replace {P = \dr' => tk ++ dr' = xs} drp $ replace {P = \tk' => tk' ++ drop o xs = xs } tkp $ takeDropConcat o xs
90+ takeDropConcat o xs
95-- Not an Iso because (=) is not extensional, but it works in spirit
92-- Not an Iso because (=) is not extensional, but it works in spirit
96||| Go through all possible inputs and tabulate the outputs in a `Vect`.
93||| Go through all possible inputs and tabulate the outputs in a `Vect`.