我在实现简单功能方面遇到了问题,我很确定答案是“护航模式”,但我无法弄清楚如何在这种特殊情况下应用它。这是一个完整的例子:
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
答案 0 :(得分: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.