Types OCaml数据结构类型中存在错误
blow是ast.ml,在ast.mli中都是相同的Types OCaml数据结构类型中存在错误,types,ocaml,Types,Ocaml,blow是ast.ml,在ast.mli中都是相同的 type ident = string type beantype = | Bool | Int | { fields : field list } | TId of ident and field = (ident * beantype) 在parser.mly中,我使用字段作为列表 typespec : | BOOL { Bool } | INT { Int } | LB
type ident = string
type beantype =
| Bool
| Int
| { fields : field list }
| TId of ident
and field =
(ident * beantype)
在parser.mly中,我使用字段作为列表
typespec :
| BOOL { Bool }
| INT { Int }
| LBRAK fields RBRAK { { fields = List.rev $2 } }
| IDENT { TId $1 }
fields :
| fields COMMA field { $3 :: $1 }
field :
| IDENT COLON typespec { ($1, $3) }
但是,存在如下错误:
ocamlc -c bean_ast.mli
File "bean_ast.mli", line 6, characters 3-4:
Error: Syntax error
make: *** [bean_ast.cmi] Error 2
为什么会出现错误?此声明:
type beantype =
| Bool
| Int
| { fields : field list }
| TId of ident
在OCaml中无效。每个变体都需要一个标记,即变体的大写标识符。你的第三个变种没有
目前还无法将新记录类型声明为变量类型的一部分
以下工作将起作用:
type ident = string
type beantype =
| Bool
| Int
| Fields of fieldrec
| Tid of ident
and fieldrec = { fields: field list }
and field = ident * beantype
我个人可能会声明类型如下:
type ident = string
type beantype =
| Bool
| Int
| Fields of field list
| Tid of ident
and field = ident * beantype
本声明:
type beantype =
| Bool
| Int
| { fields : field list }
| TId of ident
在OCaml中无效。每个变体都需要一个标记,即变体的大写标识符。你的第三个变种没有
目前还无法将新记录类型声明为变量类型的一部分
以下工作将起作用:
type ident = string
type beantype =
| Bool
| Int
| Fields of fieldrec
| Tid of ident
and fieldrec = { fields: field list }
and field = ident * beantype
我个人可能会声明类型如下:
type ident = string
type beantype =
| Bool
| Int
| Fields of field list
| Tid of ident
and field = ident * beantype