I am trying to process data from stdin in a linearly oriented fashion in OCaml, but I am having problems getting types to align with Stream.iter. I found the following code snippet on the OCaml website ( http://ocaml.org/learn/tutorials/streams.html ):
let line_stream_of_channel channel =
Stream.from
(fun _ ->
try Some (input_line channel) with End_of_file -> None)
Using this, I wrote a simple function that reads a line, does a few things, and prints some data back. I will return to the details, as I believe that the function works fine. It must be of type string -> unit, although, like (for example) print_endline, the error that I get from the compiler is the same whether I pass my function to or print_endlineto Stream.iter.
Here's the call:
let read_data =
Stream.iter ~f:print_summary (line_stream_of_channel In_channel.stdin)
The error received from the compiler is this:
Error: The function applied to this argument has type 'a Stream.t -> unit
This argument cannot be applied with label ~f
Stream.iter . , , print_endline 'a Stream.t -> unit - string -> unit, ?