Ocaml 递归函数:此表达式应具有类型unit。
此功能:Ocaml 递归函数:此表达式应具有类型unit。,ocaml,Ocaml,此功能: let rec foo () = try let line = input_line stdin in (try Mparser.tex_expr lexer_token_safe (Lexing.from_string line); print_string ("SUCCESS\n") with Mtexutil.Illegal_tex_function s -> print_string
let rec foo () =
try
let line = input_line stdin in
(try
Mparser.tex_expr lexer_token_safe (Lexing.from_string line);
print_string ("SUCCESS\n")
with
Mtexutil.Illegal_tex_function s -> print_string ("$T" ^ s ^ " " ^ line ^ "\n")
| LexerException s -> print_string ("$L" ^ line ^ "\n")
| Parsing.Parse_error -> print_string ("$P" ^ line ^ "\n")
| _ -> print_string ("$S " ^ line ^ "\n"));
flush stdout;
foo ();
with
End_of_file -> ()
;;
给出了错误:
Warning 10: this expression should have type unit.
对于以Mparser.tex开头的行
如何解决此警告 编译器似乎在警告您Mparser.tex\u expr返回一个您未使用的值。你可以通过清楚地表明你是故意放弃价值来摆脱警告。这就是ignore函数的作用:
ignore (Mparser.tex_expr lexer_token_safe (Lexing.from_string line));
在某些情况下,我认为使用let阅读效果更好。。。用分号而不是分号:
let _ = Mparser.tex_expr lexer_token_safe (Lexing.from_string line) in
...
编译器似乎在警告您Mparser.tex_expr返回一个您没有使用的值。你可以通过清楚地表明你是故意放弃价值来摆脱警告。这就是ignore函数的作用:
ignore (Mparser.tex_expr lexer_token_safe (Lexing.from_string line));
在某些情况下,我认为使用let阅读效果更好。。。用分号而不是分号:
let _ = Mparser.tex_expr lexer_token_safe (Lexing.from_string line) in
...