Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ocaml 递归函数:此表达式应具有类型unit。_Ocaml - Fatal编程技术网

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
...