coq - 在 Coq 的归纳类型中,没有 `match` 的 `with` 关键字有什么作用?
问题描述
在 Coq 的归纳类型中没有 do的with
关键字是什么?,例如:match
Inductive Block : Type :=
| EmptyBlk : Block
| Blk : Statement -> Block
with Statement : Type :=
| Assignment : string -> AExp -> Statement
| Seq : Statement -> Statement -> Statement
| IfElse : BExp -> Block -> Block -> Statement
| While : BExp -> Block -> Statement.
我尝试检查的类型,Statement
它似乎不是类型块或其他东西......那么在另一个归纳类型中定义它而不是单独定义它有什么意义。至少检查 Statement 的类型给 Set 与 Block 相同...
解决方案
它用于指定相互递归的定义。例如,考虑以下两个函数:
Fixpoint even (n : nat) : bool :=
match n with
| O => true
| S n => odd n
end
with odd (n : nat) : bool :=
match n with
| O => false
| S n => even n
end.
在这里,您不能even
先定义,因为它需要odd
定义。您也不能odd
先定义,因为它需要even
. 您需要能够同时定义两者-您可以通过使用with
关键字来做到这一点。
您的示例类似,但在其定义和用途中定义了归纳数据类型而不是递归函数 -Statement
使用。因此,同时定义它们。Block
Block
Statement
with
请注意,这是与表达式with
完全不同的关键字。事实上,它们属于两种不同的语言:前者是Vernacular的一部分,而后者是Gallina的一部分。with
match
推荐阅读
- reactjs - 无法在 React 钩子集函数中抛出错误
- django - 我使用了两个相互连接的 ChainedForeignKey 字段,但它们没有。为什么?
- python - 有没有办法让 TextInput 框自动搜索地址列表?
- google-apps-script - 如何将工作表的特定部分作为电子邮件发送?
- php - 店面功能中缺少 WooCommerce 功能
- react-native - React Native 无法访问 Net Core Web Api
- python - 如何过滤元组列表(或列表列表)以删除= 0的所有值?
- javascript - 如何从对象中删除数组?
- sql - Oracle:从列中选择总和作为两者:YTD(年初至今),Fiscal YTD
- angular - 以角度在许多组件中共享功能的最佳解决方案