<div dir="ltr"><div>Hi,</div><div><br></div><div>It&#39;s pretty clear that the toList and fromList functions in Data.Vec are in some<br>sense inverses.  One direction is easy to show:<br><br>l-v-l : ∀ {i} {A : Set i} (l : List A) -&gt; toList (fromList l) ≡ l<br>
l-v-l [] = refl<br>l-v-l (x ∷ l) = cong (λ xs → x ∷ xs) (l-v-l l)<br><br></div><div>In the other direction my first naive attempt <br><br>v-l-v : ∀ {i} {A : Set i} {n : ℕ} (v : Vec A n) -&gt; fromList (toList v) ≡ v<br>v-l-v v = ?<br>
<br></div><div>fails with Agda complaining about (fromList (toList v) ≡ v) since equality is<br>homogeneous and <br><br>   fromList (toList v)<br><br>has type<br><br>  Vec A (length (toList v))<br><br>which is not judgementally equal to the type of v, which is (Vec A n), <br>
although that equality is easy to show propositionally:<br><br>lentoList : ∀ {i} {A : Set i} {n : ℕ} (v : Vec A n) -&gt; length (toList v) ≡ n<br>lentoList [] = refl<br>lentoList (x ∷ v) = cong ℕ.suc (lentoList v)<br><br>
</div><div>My next attempt was to try to use the equality (lentoList v) as a &#39;cast&#39; to convert the type of fromList (toList v)<br><br>transport : ∀ {i j} {A : Set i} (B : A -&gt; Set j) {x y : A} -&gt; x ≡ y -&gt; B x -&gt; B y<br>
transport B refl = id<br><br>transLen : ∀ {i} {A : Set i} {n m : ℕ} -&gt; n ≡ m -&gt; Vec A n -&gt; Vec A m<br>transLen {A = A} n≡m v = transport (λ l -&gt; Vec A l) n≡m v<br><br>v-l-v : ∀ {i} {A : Set i} {n : ℕ} (v : Vec A n) -&gt;  transLen (lentoList v) (fromList (toList v)) ≡ v<br>
v-l-v [] = refl<br>v-l-v (x ∷ v) with lentoList v<br>... | eq = {! !}<br><br></div><div>but I didn&#39;t get much further since Agda does not want to case on &#39;eq&#39; as a pattern<br>variable turning it into refl.<br>
<br></div><div>My guess is there&#39;s probably a standard way around this sort of problem, or<br></div><div>a better way to express that (fromList ∘ toList) is pointwise the same as the identity.<br></div><div>But I&#39;m presently both new &amp; rusty enough not to think of it, having done just a bit of<br>
</div><div>Agda proving in the past and having been away from it for a while...<br></div><div><br></div><div>Any hints?<br><br></div><div>- Dan<br></div></div>