From: Nicolas C. <war...@fr...> - 2003-11-21 08:15:45
|
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 |