1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
(* TEST *)
open Printf
let data_file =
"input_lines_data.txt"
let length = 500
let rec check lo hi l =
if lo = hi + 1 then begin
if l <> [] then failwith "list too long"
end else begin
match l with
| [] -> failwith "list too short"
| h :: t ->
if int_of_string h <> lo then failwith "wrong value";
check (lo + 1) hi t
end
let _ =
Out_channel.with_open_text data_file
(fun oc ->
fprintf oc "0";
for i = 1 to length do fprintf oc "\n%d" i done);
In_channel.with_open_text data_file In_channel.input_lines
|> check 0 length;
In_channel.with_open_text data_file
(In_channel.fold_lines (fun accu line -> line :: accu) [])
|> List.rev
|> check 0 length;
Sys.remove data_file
|