【发布时间】:2013-01-23 07:15:27
【问题描述】:
好吧,我在 OCaml 中使用 semicolon (single and double) 和 nested if else 时遇到问题。
例如
let union u p q =
let rec unionfy id_ary i =
if i < Array.length id_ary then begin
if id_ary.(i) = p then begin
id_ary.(i) <- id_ary.(q);
print_array id_ary 0;
end
unionfy id_ary (i + 1);
end
else print_string "end of union";
in
unionfy u.id_ary 0;;
编译器说line 18, characters 29-95:
Error: This expression is not a function; it cannot be applied
有问题的线路是if id_ary.(i) = p then begin,但我不明白为什么。
另外,谁能告诉我更多关于semicolon 和nested if else 的信息?
我想到了一些问题:
- 什么时候使用
single semicolon?如果我将它用于多个表达式,是否必须在最后一个表达式后添加double semicolon? 我可以在
nested if中使用多个begin end吗?如果结果是
unit and do nothing,好像不需要加else?
【问题讨论】:
标签: functional-programming ocaml