I tried this code, followed by
let test = In_channel.with_open_text "test.txt" numbered_lines
let () = Seq.iter (fun _ -> ()) test
but in utop, I get:
utop # let test = In_channel.with_open_text "test.txt" numbered_lines;;
val test : (int * string) Seq.t = <fun>
utop # let () = Seq.iter (fun _ -> ()) test;;
Exception: (Sys_error "Bad file descriptor").
Raised by primitive operation at Stdlib.input_line.scan in file "stdlib.ml", line 453, characters 12-32
Called from Stdlib.input_line in file "stdlib.ml", line 471, characters 28-39
Called from unknown location
Called from Stdlib__Seq.unfold in file "seq.ml", line 80, characters 8-11
Called from Stdlib__Seq.iter in file "seq.ml", line 73, characters 8-14
Called from unknown location
Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
Called from Topeval.load_lambda in file "toplevel/byte/topeval.ml", line 89, characters 4-150
I do not know where this error comes from. The file test.txt
itself is ok, since I get
utop # In_channel.(with_open_text "test.txt" (fun ic -> input_line ic));;
- : string option = Some "Ceci est un test."