1

我在实现简单功能时遇到问题,我很确定答案是“护航模式”,但我只是不知道如何在这种特殊情况下应用它。这是一个完整的例子:

Require Import Coq.Lists.List.

Definition index_map_spec (domain range: nat) :=
  forall n : nat, n < domain -> {v : nat | v < range}.

Lemma lt_pred_l {n m} (H: S n < m): n < m.
Proof. auto with arith. Defined.

Fixpoint natrange_f_spec
         (n:nat)
         {i o: nat}
         (nd: n<i)
         (f_spec: index_map_spec i o)
  : list nat
  :=
    match n return list nat with
    | 0 => nil
    | S n' => cons n' (natrange_f_spec n' (lt_pred_l nd) f_spec)
    end.

我得到的错误是:

The term "nd" has type "n < i" while it is expected to have type
 "S ?578 < ?579".

所以基本上我想以某种方式匹配 'n' 对于 (n=S p) 它会重写 (n

4

1 回答 1

3

你只需要抽象出nd你的证明match,相应地改变它的返回类型:

Require Import Coq.Lists.List.

Definition index_map_spec (domain range: nat) :=
  forall n : nat, n < domain -> {v : nat | v < range}.

Lemma lt_pred_l {n m} (H: S n < m): n < m.
Proof. auto with arith. Defined.

Fixpoint natrange_f_spec
         (n:nat)
         {i o: nat}
         (nd: n<i)
         (f_spec: index_map_spec i o)
  : list nat
  :=
    match n return n < i -> list nat with
    | 0 => fun _ => nil
    | S n' => fun nd => cons n' (natrange_f_spec n' (lt_pred_l nd) f_spec)
    end nd.
于 2015-08-17T22:18:16.850 回答