ocaml - 这个 ocaml 代码段是什么意思?
问题描述
我无法从 ocaml 编译器源代码中理解这个 ocaml 代码:
File: d:\src\ocaml-4.07.0\driver\pparse.ml
50: type 'a ast_kind =
51: | Structure : Parsetree.structure ast_kind
52: | Signature : Parsetree.signature ast_kind
有定义一个类型ast_kind,定义类型参数'a,但不使用它?
我知道类型定义的常见用法是这样的:
type a=
|A of int
|B of int
所以
Structure : Parsetree.structure ast_kind
是什么意思?Structure 的类型是 Parsetree.structure?还是 ast_kind?
我阅读了官方文档: http ://caml.inria.fr/pub/docs/manual-ocaml-312/manual016.html#@manual.kwd53
它告诉我只有在记录的定义中才能使用“:”
type-representation ::= = constr-decl { | constr-decl }
∣ = { field-decl { ; field-decl } }
field-decl ::= field-name : poly-typexpr
∣ mutable field-name : poly-typexpr
那么这段代码是什么意思呢?谢谢!
解决方案
从...开始 :
50: type 'a ast_kind =
51: | Structure : Parsetree.structure ast_kind
52: | Signature : Parsetree.signature ast_kind
内容如下:
第 50 行:我们定义了一个参数化类型ast_kind
,其参数为'a
. 该参数稍后在第 51 行和第 52 行中定义。在第 51 行:'a
参数类型是Parsetree.structure
And 与第 52 行类似。
现在,更一般地说,ast_kind
是 GADT 类型(广义代数数据类型),请参阅GADT 手册和另一个示例:Mads-hartmann。
请注意,GADT 已在 Ocaml 4.00 中引入 - 因此您引用的有关文档的链接对于该特定功能已过时,因为它指的是 Ocaml 3.12。您当前正在检查 Ocaml 4.07 的源代码。
推荐阅读
- android - 如何在没有任何 clickListener 的情况下使用带有 EventBus 的导航 - android
- c++ - CPP 中的 Valgrind 和内存泄漏:“条件跳转或移动取决于未初始化的值”
- python - 如何在不导入 RAM 的情况下使用 numpy 文件?
- javascript - GeoJson 图层中的特征与 Autocad 中的角度不同
- azure - 在哪里可以找到 Azure 登录活动报告错误代码列表?
- node.js - 如何从两个表中验证登录信息
- c# - 用链接替换html正文中的标签而不匹配C#中的内联CSS
- javascript - Javascript如何获取绝对路径?
- c++ - 如何在新的派生对象中获取基础对象的数据?
- python - 边缘检测 灰度图像