此表达式的类型为Sast.var_decl,但表达式的类型应为Ast.var_decl(使用Ocaml编写编译)
我正在使用Ocaml编写一个小型编译器。我想打字检查Ast,然后输入Sast 但我总是得到如下错误:此表达式的类型为Sast.var_decl,但表达式的类型应为Ast.var_decl(使用Ocaml编写编译),ocaml,Ocaml,我正在使用Ocaml编写一个小型编译器。我想打字检查Ast,然后输入Sast 但我总是得到如下错误: File "typecheck_debug.ml", line 93, characters 28-35: Error: This expression has type Sast.var_decl but an expression was expected of type Ast.var_decl 代码是: let rec trans_lval e
File "typecheck_debug.ml", line 93, characters 28-35:
Error: This expression has type Sast.var_decl
but an expression was expected of type Ast.var_decl
代码是:
let rec trans_lval env = function
Ast.Id(n) -> let vdecl = (find_variable env.scope n) in
Sast.Id(vdecl), vdecl.vvtype
ocamllex scanner.mll
ocamlyacc parser.mly
ocamlc -c ast.mli
ocamlc -c parser.mli
ocamlc -c scanner.ml
ocamlc -c parser.ml
ocamlc -c sast.mli
ocamlc -c typecheck_debug.ml
我不明白为什么。我的项目过程有什么问题吗?仅从那一点点代码就很难分辨,但它听起来像
Sast.Id
需要一个类型为Sast.var_decl
的值作为其参数,但find_variable
生成一个类型为Ast.var_decl
的值,因此这就是vdecl
的类型
我在这里假设第93行,字符28-35是
(vdecl)
。如果不是这样的话,请澄清。很难仅从那一点点代码中分辨出来,但听起来好像Sast.Id
期望一个类型为Sast.var_decl
的值作为其参数,但find_variable
生成一个类型为Ast.var_decl
的值,因此这就是vdecl
的类型
我在这里假设第93行,字符28-35是
(vdecl)
。如果不是这样,请澄清。另一种可能性是,问题不在那里,而是在函数的另一个分支trans\u lval
(您没有显示,但必须有其他分支,您的ast不能仅由Id
组成)。检查代码的哪一部分是罪魁祸首的简单方法包括:
let rec trans_lval : Ast.lval -> Sast.lval = function
(* code follows *)
(这可能是错误的,我显然无法从您提供的信息中分辨出您函数的真正类型)另一种可能性是,问题不存在,而是在函数的另一个分支中
trans\u lval
(您没有显示,但必须有其他分支,您的ast不能仅由Id
s组成)。检查代码的哪一部分是罪魁祸首的简单方法包括:
let rec trans_lval : Ast.lval -> Sast.lval = function
(* code follows *)
(这可能是错误的,我显然无法从您提供的信息中分辨出您函数的真正类型)有助于查看ast.mli和sast.mli的相关章节。可能的相关项目:有助于查看ast.mli和sast.mli的相关章节。可能的相关项目: