在java
中我们可以写result?1:0
。这是根据 result bool
获取值的快捷方式。
如何在 OCaml 中编写这样的东西?
最佳答案
听起来这是一个重复的问题。但是请注意,OCaml 中的所有内容都是表达式。所以答案是if result then 1 else 0
。您可能需要根据上下文将其括起来。 (在 C 系列中,我有时用于表达的形式是 !!result
。)
关于functional-programming - 如何在 OCaml 中写入 `result?1:0`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367254/