From: Nicolas C. <war...@fr...> - 2004-01-14 21:40:02
|
I'm forwarding this message to the extlib list. I sent this one a couple of weeks ago but didn't get any answer, I'm not sure that it reached the list back then. > Hi list, > > I just took some time to write a little module for handling IO in an > abstract way. > Several times I hit into some things that I wanted to print either in a > string or in a file, here is some beginning of answer to this problem. > > For efficiency reason each input/output have two ways of reading/writing > data : for example a chanr nel input can write char by char or directly > strings. it's then a (char,string) input. An ouput takes a third parameter > which is the value returned by a call to close. > > Then you can do the following : > > let o = IO.output_string() in > IO.printf o "hello world %c" '!'; > let s = IO.close_out o in > print_endline s > > which is equivalent to : > > let o = IO.output_channel stdout in > IO.printf o "hello world %c" '!'; > IO.close_out o; // are you sure :-) > > Comments are of course welcome, > > Nicolas Cannasse > |