3
我想通過Coq中的兩個參數定義一個嵌套的遞歸函數。與部分應用程序嵌套遞歸
Require Import List.
Import ListNotations.
Fixpoint map_sequence2 {A B C : Set} (f : A -> B -> option C)
(xs : list A) (ys : list B) : option (list C) :=
match xs, ys with
| [], [] => Some []
| x :: xs, y :: ys =>
match f x y, map_sequence2 f xs ys with
| Some z, Some zs => Some (z :: zs)
| _, _ => None
end
| _, _ => None
end.
Inductive T : Set := TA | TB : list T -> T.
Definition max n m := if Nat.leb n m then m else n.
Fixpoint height (t : T) : nat :=
match t with
| TA => 1
| TB xs => 1 + List.fold_left max (List.map height xs) 0
end.
Function bar (t1 : T) (t2 : T) {measure height t2} : option T :=
match t1, t2 with
| TA, TA => Some TA
| TB xs, TB ys =>
match map_sequence2 bar xs ys with
| Some zs => Some (TB zs)
| None => None
end
| _, _ => None
end.
Proof.
Abort.
,但我得到了以下錯誤:
Error: No such section variable or assumption: bar.
的Function
文檔明確地說:
Function does not support partial application of the function being defined.
但是,這正是我的情況。這種情況下的策略是什麼?
謝謝,它的工作原理!有沒有一些文獻可以更好地瞭解終止預言? – authchir
手冊中有[此說明](https://coq.inria.fr/distrib/current/refman/gallina.html#sec57)。或許,[這篇Cocrico文章](https://coq.inria.fr/cocorico/CoqTerminationDiscussion)可能會有所幫助。 –