Recursion 在不动点Coq定义中使用lambda
我试图在递归定义中使用Recursion 在不动点Coq定义中使用lambda,recursion,coq,dependent-type,Recursion,Coq,Dependent Type,我试图在递归定义中使用List.map,使用当前定义的递归函数作为参数映射列表。有可能吗?我可以定义自己的递归不动点定义,而不是使用map,但我对这里使用map感兴趣 Require Import Coq.Lists.List. Import ListNotations. Inductive D: nat -> Type := | D0 (x:nat): D x. Inductive T: nat -> nat -> Type := | T0 {i o} (foo:nat)
List.map
,使用当前定义的递归函数作为参数映射列表。有可能吗?我可以定义自己的递归不动点定义,而不是使用map
,但我对这里使用map
感兴趣
Require Import Coq.Lists.List.
Import ListNotations.
Inductive D: nat -> Type := | D0 (x:nat): D x.
Inductive T: nat -> nat -> Type :=
| T0 {i o} (foo:nat): T i o
| T1 {i o} (foo bar:nat) : T i o -> T i o.
Fixpoint E {i o: nat} (t:T i o) (x:nat) (d:D i): option (D o)
:=
(match t in @T i o
return D i -> option (D o)
with
| T0 _ _ foo => fun d0 => None
| T1 _ _ foo bar t' =>
fun d0 =>
let l := List.map (fun n => E t' x d0) [ 1 ; 2 ; 3 ] in
let default := Some (D0 o) in
List.hd default l
end) d.
上面的例子是人为的,但说明了问题所在。错误消息:
The term "l" has type "list (option (D n0))"
while it is expected to have type "list (option (D o))".
您只需要绑定
T1
模式上的名称:
Require Import Coq.Lists.List.
Import ListNotations.
Inductive D: nat -> Type := | D0 (x:nat): D x.
Inductive T: nat -> nat -> Type :=
| T0 {i o} (foo:nat): T i o
| T1 {i o} (foo bar:nat) : T i o -> T i o.
Fixpoint E {i o: nat} (t:T i o) (x:nat) (d:D i): option (D o)
:=
(match t in @T i o
return D i -> option (D o)
with
| T0 _ _ foo => fun d0 => None
(* \/ change here *)
| T1 i o foo bar t' =>
fun d0 =>
let l := List.map (fun n => E t' x d0) [ 1 ; 2 ; 3 ] in
let default := Some (D0 o) in
List.hd default l
end) d.
问题是省略binder意味着
T1
分支上使用的o
引用相同名称的“外部”变量,而您希望它引用由T1
给出的变量,谢谢!这很奇怪。我之前尝试过这个,它生成了新的变量名(i0,o0而不是I,o)。但在这个例子中,它现在起作用了。也许这是一些封闭代码的影响。