From: Manos R. <er...@cs...> - 2003-03-01 00:47:52
|
On Fri, Feb 28, 2003 at 12:38:12PM +0900, Nicolas Cannasse wrote: > > (* fold left on file lines (without trailing newline), I don't know in > > which module this functions should go, maybe Sys? *) > > - val fold_file : ('a -> string -> 'a) -> 'a -> string -> 'a > > (* iter on file lines *) > > - val iter_file : (string -> unit) -> string -> unit > > perhaps : > > val iter_in : (string -> unit) -> in_channel -> unit > val map_in : (string -> 'a) -> in_channel -> 'a list > val fold_in : ('a -> string -> 'a) -> 'a -> in_channel -> 'a > > are better so it can work on many kind of descriptors and does not have to > handle the "file not found" problems > > I propose also : > > val read_lines : in_channel -> string list > val read_all : in_channel -> string > > that returns all the contents ( up to End_of_file ) I think that all of those can be done much better with Streams (the streams that are in the Stream standard module). Something like Stream.of_lines (ic:in_channel) : string Stream.t Of course, that means that we need the equivalent iter, map, and fold in Stream, like val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b Stream.t -> 'a val map : ('a -> 'b) -> 'a Stream.t -> 'b Stream.t -- Manos |