【发布时间】:2018-11-06 08:42:42
【问题描述】:
我无法从 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
那么这段代码是什么意思呢?谢谢!
【问题讨论】:
标签: ocaml