首页 > 解决方案 > 之后在 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 ..

谢谢你帮助我

标签: ocaml

解决方案


您可以参考https://caml.inria.fr/pub/old_caml_site/FAQ/qrg-fra.html的§Séquence 。

通常,您必须在 if-then-else 结构中对 ocaml 语句进行分组,方法是使用显式beginend关键字,或者使用括号对序列进行分组。


推荐阅读