修改
Require Import Bool List ZArith.
Variable A: Type.
Inductive error :=
| Todo.
Inductive result (A : Type) : Type :=
Ok : A -> result A | Ko : error -> result A.
Variable bool_of_result : result A -> bool.
Variable rules : Type.
Variable boolean : Type.
Variable positiveInteger : Type.
Variable OK: result unit.
Definition dps := rules.
Inductive dpProof :=
| DpProof_depGraphProc : list
(dps * boolean * option (list positiveInteger) * option dpProof) -> dpProof.
Fixpoint dpProof' (R D: rules) (p: dpProof) {struct p}:=
match p with
| DpProof_depGraphProc cs => dpGraphProc R D cs
end
with dpGraphProc (R D: rules ) cs {struct cs} :=
match cs with
| nil => Ko unit Todo
| (_, _, _, op) :: cs' =>
match op with
| None => Ko unit Todo
| Some p2 => dpProof' R D p2
end
end.
我收到一条错误消息说: 对dpProof的递归调用具有等于
的主参数"p2" instead of "cs'".
Recursive definition is:
"fun (R D : rules)
(cs : list
(dps * boolean * option (list positiveInteger) *
option dpProof)) =>
match cs with
| nil => Ko unit Todo
| (_, _, _, Some p2) :: _ => dpProof' R D p2
| (_, _, _, None) :: _ => OK
end".
如果我不使用相互递归并使用嵌套的fixpoint,它将组合并传递终止检查器。这是成功组合的代码。
Fixpoint dpProof' (R D: rules) (p: dpProof) {struct p}:=
match p with
| DpProof_depGraphProc cs =>
match cs with
| nil => Ko _ Todo
| (_, _, _, op) :: cs' =>
match op with
| None => Ko unit Todo
| Some p2 => dpProof' R D p2
end
end end.
我想更深入地了解它无法通过终止检查器的原因?是因为他们无法猜测减少的论点吗?有什么方法可以使用相互递归来表达我的函数dpGraphProc
?
另外,我如何编写检查整个列表的函数dpGraphProc
?在这里,我不知道如何使用参数cs'
。
答案 0 :(得分:4)
相互递归既可以用于单个归纳数据类型,也可以用于在单个归纳定义中一起定义的不同归纳数据类型。在您的情况下,您使用的是在dpProof之前已经定义的多态数据类型prod(对的类型),列表和选项。
嵌套的fixpoint方法没有限制。