extracting evidence of equality from match

老子叫甜甜 提交于 2019-12-23 17:20:20

问题


I am trying to make the following work:

    Definition gen `{A:Type}
           {i o: nat}
           (f: nat -> (option nat))
           {ibound: forall (n n':nat), f n = Some n' -> n' < i}
           (x: svector A i) (t:nat) (ti: t < o): option A
  := match (f t) with
     | None => None
     | Some t' => Vnth x (ibound t t' _)
     end.

In place of last "_" I need an evidence that "f t" is equals to "Some t'". I could not figure out how to get it from the match. Vnth is defined as:

Vnth
     : ∀ (A : Type) (n : nat), vector A n → ∀ i : nat, i < n → A

回答1:


Writing this function requires an instance of what is known as the convoy pattern (see here). I believe the following should work, although I can't test it, since I don't have the rest of your definitions.

Definition gen `{A:Type}
           {i o: nat}
           (f: nat -> (option nat))
           {ibound: forall (n n':nat), f n = Some n' -> n' < i}
           (x: svector A i) (t:nat) (ti: t < o): option A
  := match f t as x return f t = x -> option A with
     | None => fun _ => None
     | Some t' => fun p => Vnth x (ibound t t' p)
     end (eq_refl (f t)).


来源:https://stackoverflow.com/questions/31576238/extracting-evidence-of-equality-from-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!