ocaml - 之后在 Ocaml 中的两个动作
问题描述
是否可以在 Ocaml 中的 then 之后进行两个操作?我尝试搜索,发现可以使用分号。我应该这样使用它吗?:
let test (a:int)=
if a = 0
then print_int(1);print_int(2)
else()
;;
这只是一个例子。就我而言,我想启动一个函数并给出一个这样的元组:
let move_square(x,y:int*int):int*int=
..
let direction : int = Random.int(5);
if direction = 0
then draw_square(x,y+1);x,y+1
else ..
谢谢你帮助我
解决方案
您可以参考https://caml.inria.fr/pub/old_caml_site/FAQ/qrg-fra.html的§Séquence 。
通常,您必须在 if-then-else 结构中对 ocaml 语句进行分组,方法是使用显式begin
和end
关键字,或者使用括号对序列进行分组。
推荐阅读
- pine-script - Pinescript - 为什么在触发 strategy.exit() 时不能正确调整 strategy.position_avg_price?
- erlang - Erlang:函数在 shell 中工作,但不在 YAWS 中
- java - Java - Android Studio - .xml 文件不存在错误
- python - 如何在python pandas中合并重复的行
- go - 陷入 Go 并行测试(与微服务连接的自动化测试)
- java - SPEL - 拆分和修剪,分隔值
- java - 将 Apache POI 导入 eclipse 项目并使其在另一台计算机上可用
- python-3.x - 使用 Python (3.7) 在 OpenCV (4.2.0) 中检测矩形,
- node.js - 如何解决语法错误、意外标记、导出类型?
- php - 如何在 5 分钟内使 WooCommerce 购物车过期?尝试使用过滤器挂钩但无法使其工作