I have been working on trying to understand this, and working any harder on it is going to hurt my relationship with OCaml, so I figured I would ask for help.
I have a simple function from this site
let line_stream_of_channel channel =
Stream.from
(fun _ ->
try Some (input_line channel) with End_of_file -> None);;
Okay cool, clearly from the signature below it:
val line_stream_of_channel : in_channel -> string Stream.t = <fun>
in_channel is the argument and Stream.t is the return value.
Now why is it in OCaml that I can't do:
Stream string
and instead I have to do
string Stream.t
Looking at the type signature of Stream didn't really get me anywhere either. I've noticed this same syntax weirdness with stuff like lists where you have to do the unnatural
string list
rather than the natural
list string
But what is especially weird is the ".t" portion of the Stream type above.
Can anyone kinda explain what is going on here and why things are done this way? I've googled tutorials on explicit type signatures, types, etc in OCaml and in general they lead back here to very specific questions that don't really help me.
Thank you!