coq - 为什么 FMapAVL 在参数中的使用不是严格正数,而列表却是严格正数?

标签 coq

考虑以下代码:

Require Import FMapAVL.
Require Import Coq.Structures.OrderedTypeEx.

Module NatMap := FMapAVL.Make(Nat_as_OT).

Inductive ttree (K : Type) (V : Type) :=
| tleaf : ttree K V
| tnode : ttree K V -> K -> V -> ttree K V -> nat -> ttree K V.

Inductive test :=
| test1 : test
| test2 : ttree nat test -> test   
| test3 : list test -> test
| test4 : NatMap.t test -> test.

在 Coq 8.6 中,我得到错误:“NatMap.t test -> test”中“test”的非严格正数出现。如果没有 test4,我不会得到任何错误.

为什么将 NatMap.t(带有 nat 键的 FMapAVL)构造函数应用于我的 test 归纳类型在应用 list 构造函数甚至 ttree 构造函数(就像 FMapAVL 的内部结构)时创建一个非严格正的事件,好吗?

如果我想要示例中的 test4 之类的内容,最好是不需要我自己制作像 ttree 这样的 map 实现,那么常见的解决方法是什么?

最佳答案

问题是 Coq 无法将某些高阶归纳类型作为嵌套归纳处理 - 我不确信我完全理解这些限制,但我进行了一些调查。

有助于解释该行为的一个重要事实是 Coq 对将归纳类型传递给类型构造函数有特殊支持。 CPDT's Inductive Types本章在嵌套归纳类型部分对此进行了解释:Coq 创建专门用于 testlistttree 版本,并假装您正在定义 tree 和这些具有互归纳功能的专门归纳法。这通常工作得很好(例如对于您的 list 甚至 ttree 定义)。它甚至适用于模块,只要它们使用“transparent ascription ”(并且 FMapAVL.Make 就是这样做的)。但是,当类型是索引而不是参数时(即,当 Type 位于冒号右侧而不是左侧时),它似乎会崩溃:

Module Type Transformer.
  Axiom T:Type -> Type.
End Transformer.

Module IdOpaque : Transformer.
  Definition T (t:Type) := t.
End IdOpaque.

Inductive transformer : Type -> Type :=
| MkT : forall t, t -> transformer t .

(* make the argument a parameter *)
Inductive transformer' (t:Type) : Type :=
| MkT' : t -> transformer' t.

Module IdInd <: Transformer.
  Definition T : Type -> Type := transformer.
End IdInd.

Module IdTransparent <: Transformer.
  Definition T (t:Type) : Type := t.
End IdTransparent.

(* works with a simple definition, even inside a module, as long as its
transparent *)
Inductive test1 :=
| mkTest1 (_:IdTransparent.T test1).

(* not strictly positive (Coq can't see definition) *)
Fail Inductive test2 :=
| mkTest2 (_:IdOpaque.T test2).

(* this is pretty much what happens with FMapAVL.Make *)
Fail Inductive test3 :=
| mkTest3 (_:IdInd.T test3).

(* even this fails *)
Fail Inductive test4 :=
| mkTest4 (_:transformer test4).

(* this finally works *)
Inductive test5 :=
| mkTest5 (_:transformer' test5).

关于coq - 为什么 FMapAVL 在参数中的使用不是严格正数,而列表却是严格正数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49844617/

相关文章:

Coq:为什么我需要手动展开一个值,即使它上面有 `Hint Unfold`?

coq - 证明群中的一般结合性

coq - 用无法证明的子目标卡住证明引理

functional-programming - Coq 中 Definition 和 Let 的区别

functional-programming - Coq 通过两种实现对阶乘程序进行验证

import - 不要在 coq 中导入符号

coq - 如何从明显矛盾的假设中证明 False

coq - 当 simpl 没有减少所有必要的步骤时应该怎么办?

coq - 如何在 Coq 的假设中实例化 forall 的变量?

types - 如何在 coq 中定义自定义归纳原理?