我是Ocaml的初学者,我似乎无法理解这种语法。我必须编写一个不返回布尔值求反的函数。
我写了这个:
let not x =
match x with
true -> false
| false -> true;
if (not false) then Printf.printf "True !"
但是它拒绝编译,有人可以给我一个提示吗?
错误消息是:
Error: This expression has type unit but an expression was expected of type bool
在最后一行。
根据https://baturin.org/docs/ocaml-faq/#the-double-semicolon,在交互式REPL中,您需要使用;;
结束您的陈述:
在您的帮助下,这似乎是我打算编写的代码: