我现在正在尝试学习OCaml,想从一个小程序开始,生成所有的位组合:
["0","0","0"]
["0","0","1"]
["0","1","0"]
我的想法是以下代码:
let rec bitstr length list =
if length = 0 then
list
else begin
bitstr (length-1)("0"::list);
bitstr (length-1)("1"::list);
end;;
但是我遇到了以下错误:
Warning S: this expression should have type unit.
val bitstr : int -> string list -> string list = <fun>
# bitstr 3 [];;
- : string list = ["1"; "1"; "1"]
我不明白需要改变什么,你可以帮助我吗?
最好的祝福 Philipp