ocaml - 如何用unit()包装OCaml表达式?

标签 ocaml

以下表达式 3 ; utop 中的 () 会产生以下响应

utop # 3 ; ();;
Characters 0-1:
Warning 10: this expression should have type unit.
Characters 0-1:
Warning 10: this expression should have type unit.
- : unit = ()

如何使非 unit 表达式(例如 3)返回 unit 来与分号运算符一起使用?

最佳答案

有一个函数ignore就是为了这个目的。

# ignore 3; ();;
- : unit = ()
#

关于ocaml - 如何用unit()包装OCaml表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55424742/

相关文章:

module - 在使用 Base 的 OCaml 中,如何构造一个包含类型为 `int * int` 的元素的集合?

ocaml - OCaml 中两个列表之间比较的复杂性是什么?

ocaml - 从 LLVM 字符串常量中获取字符串

data-structures - 在 OCaml 中使用数据结构的正确方法

OCaml 自定义编译器警告

ocaml - 在 OCaml 中一起使用 List.exists、List.for_all 和 List.filter

c++ - 从 Ruby 代码访问以 OCaml 和 C++ 编写的库

ocaml - 从 OCaml 调用 C/汇编函数比使用 caml_c_call 更直接

ocaml - 使用 OCaml 电池作为普通 cma 包含在内

ocaml - 通过 ocamlbuild 在 .mly 文件中使用电池