代数类型的 Coq 到 OCaml 提取

Coq to OCaml extraction of algebraic types

当我将以下 Coq 数据类型提取到 OCaml 时:

Inductive Foo := | A | B.
Inductive Bar (f:Foo) := | C | D.
Extraction Language Ocaml.
Extraction "test.ml" Foo Bar.

我得到以下 ML 代码:

type foo =
| A
| B

type bar =
| C
| D

'bar' 类型与 Coq 的类型不同,因为它确实将 'f' 作为其类型签名的一部分。

定义此类类型以便将它们很好地提取到 OCaml 的最佳方法是什么?

你不能:OCaml 不支持按术语值索引类型,因此 Bar A 之类的东西在其中没有意义。 Coq 被迫删除额外的索引,以便定义与 OCaml 的类型系统兼容。