extracting evidence of equality from match

246 views Asked by At

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

There are 1 answers

0
Arthur Azevedo De Amorim On BEST ANSWER

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)).