@@ -29,7 +29,7 @@ splitPair {n} {m} = MkIso (splitAt n) (uncurry (++)) toFrom fromTo
2929 where pairify : q = w -> e = r -> (q, e) = (w, r)
3030 pairify Refl Refl = Refl
3131 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
3333
3434||| An `Iso` based on `zip` and `unzip`.
3535zipped : Iso (Vect n a, Vect n b) (Vect n (a, b))
@@ -68,7 +68,8 @@ transposition {a} = MkIso transpose transpose prf prf
6868||| This is the inverse of `concat`.
6969unconcat : Vect (n * m) a -> Vect n (Vect m a)
7070unconcat {n = Z} [] = []
71−unconcat {n = S k} {m} xs = let (xs', xss) = splitAt m xs in xs' :: unconcat xss
71+unconcat {n = S k} {m} xs with (splitAt m xs)
72+ | (xs', xss) = xs' :: unconcat xss
7273||| An `Iso` based on `unconcat` and `concat`.
7374|||
7475||| ```idris example
@@ -76,21 +77,17 @@ unconcat {n = S k} {m} xs = let (xs', xss) = splitAt m xs in xs' :: unconcat xss
7677||| ```
7778rectangular : Iso (Vect (n * m) a) (Vect n (Vect m a))
7879rectangular = MkIso unconcat concat toFrom fromTo
79−-- TODO: Clean up after #4001 is fixed
8080 where toFrom : (xss : Vect i (Vect o a)) -> unconcat (concat xss) = xss
8181 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)
84− tkp = trans (sym $ takePrefix xs $ concat xss) $ cong {f=fst} sATK
85− drp = trans (sym $ toFrom xss) $ cong {f=unconcat} $ trans (sym $ dropPrefix xs $ concat xss) $ cong {f=snd} sATK
86− in replace {P = \dr' => tk :: dr' = xs :: xss} drp $ replace {P = \tk' => tk' :: xss = xs :: xss} tkp Refl
82+ toFrom {i = S i} {o} (xs :: xss) = rewrite splitAtTakeDrop o {m = i * o} (xs ++ concat xss) in
83+ rewrite takePrefix xs (concat xss) in
84+ rewrite dropPrefix xs (concat xss) in
85+ cong (toFrom xss)
8786 fromTo : (xs : Vect (i * o) a) -> concat (unconcat xs) = xs
8887 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
91− tkp = cong {f=fst} sATK
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
88+ fromTo {i = S i} {o} xs = rewrite splitAtTakeDrop o {m = i * o} xs in
89+ rewrite fromTo {i} {o} (drop o xs) in
90+ takeDropConcat o xs
9491
9592-- Not an Iso because (=) is not extensional, but it works in spirit
9693||| Go through all possible inputs and tabulate the outputs in a `Vect`.