I'm trying to learn ocaml right now and wanted to start with a small program, generating all the bit combinations: ["0", "0", "0"] ["0", "0", "1"] ["0", " 1 "," 0 "] ... etc.
My idea is the following code:
let rec bitstr length list =
if length = 0 then
list
else begin
bitstr (length-1)("0"::list);
bitstr (length-1)("1"::list);
end;;
But I get the following error:
Warning S: this expression should have type unit.
val bitstr : int -> string list -> string list = <fun>
# bitstr 3 [];;
- : string list = ["1"; "1"; "1"]
I did not understand what to change, can you help me?
Regards Philipp
source
share