coq - 如何在 Coq 中为 Big Step 和 Small Step 语义定义一个单一的配置?
问题描述
我试图定义有助于语句/代码/程序/算术/布尔表达式的配置,但我发现自己必须为似乎不必要的每种类型定义一个。是否可以在 Coq 中以某种方式合并所有不同的情况?
Inductive BigConfig : Type :=
| B_AExpConf : AExp -> State -> BigConfig
| B_BExpConf : BExp -> State -> BigConfig
| B_StmtConf : Statement -> State -> BigConfig
| B_BlkConf : Block -> State -> BigConfig
| B_StateConf : State -> BigConfig
| B_PgmConf : Program -> BigConfig.
然后我注意到我也有大步和小步的单独配置。是否可以将它们合并为 1 个单一配置?
Inductive SmallConfig : Type :=
| S_AExpConf : AExp -> State -> SmallConfig
| S_BExpConf : BExp -> State -> SmallConfig
| S_StmtConf : Statement -> State -> SmallConfig
| S_BlkConf : Block -> State -> SmallConfig
| S_PgmConf : Program -> SmallConfig.
解决方案
正如我在评论中所说, aBigConfig
是SmallConfig + State
,意思是,如果你SmallConfig
像你一样定义:
Inductive SmallConfig : Type :=
| S_AExpConf : AExp -> State -> SmallConfig
| S_BExpConf : BExp -> State -> SmallConfig
| S_StmtConf : Statement -> State -> SmallConfig
| S_BlkConf : Block -> State -> SmallConfig
| S_PgmConf : Program -> SmallConfig.
那么定义的一种方法BigConfig
是:
Definition BigConfig : Type := sum SmallConfig State.
然后,您必须对( / ) 和案例中的构造函数进行模式匹配,而不是对BigConfig
构造函数(不再存在)进行模式匹配。sum
inl
inr
SmallConfig
inl
match bconf with
| inl (S_AExpConf a s) => ...
| inl (S_BExpConf b s) => ...
...
| inr s (* this represents B_StateConf *) => ...
end
推荐阅读
- sql - 有没有办法在添加间隔的同时保留一个月的最后一天?
- angular-tree-component - 角树组件虚拟滚动不起作用
- mysql - 如何从 MySQL JSON 数组中选择行?
- python - 将排序表从熊猫数据框发送到前端?
- html - Jekyll:插入前面的内容后找不到页面
- testrigor - 我怎样才能让 testRigor 以正确的方式找到这个输入?
- cakephp - CakePHP Bake :: 在 bake 命令上创建元素文件
- r - geom_density 返回图而不考虑实际值
- reactjs - 如何在 Typescript 中输入匹配项?
- spring-integration - 回复后可以收到原始消息吗