Hi, i’ve been trying to create a program that reads the lines from a file, formats them a certain way and then prints them out. Here is what my main looks like:
let () =
In_channel.create (Sys.get_argv()).(1)
|> extract
|> iter_stream ~f:(fun (f,c,l) -> printf " %s %s %s \n" f c l" )
My extract function has this type:
val extract: In_channel -> (string*string*string) stream
The problem i’m running into is that creating this function:
let rec iter_stream st ~f =
val iter_stream: 'a stream -> ('a -> unit) -> unit
I had no trouble with creating a stream and formating the lines inside of it but when it comes to iterating it and ~f i just get lost.
I see, it didn’t make any sense to use None and Some indeed.
Cons(x, st') -> f x; stream_iter st' ~f
Regarding the second point, even if i match the stream with Cons (x, st'), i can’t pass the st' as the argument to the recursive function since st' is not a stream. Looking at the type definition st' in this case is of type a' stream thunk. How can i get a' stream type to pass it as argument.