首页 > 解决方案 > 如何用 unit() 包装 OCaml 表达式?

问题描述

utop 中的以下表达式3 ; ()导致以下响应

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以使用分号运算符?

标签: ocaml

解决方案


有一个功能ignore就是为了这个目的。

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

推荐阅读