Ocaml语法与布尔值匹配

问题描述 投票:1回答:2

我是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 在最后一行。

syntax compiler-errors ocaml
2个回答
0
投票

根据https://baturin.org/docs/ocaml-faq/#the-double-semicolon,在交互式REPL中,您需要使用;;结束您的陈述:


0
投票

在您的帮助下,这似乎是我打算编写的代码:

© www.soinside.com 2019 - 2024. All rights reserved.