From: Nicolas C. <war...@fr...> - 2004-04-25 20:43:45
|
Here's some OO wrappers proposal for IO module. As Yamagata Yoriyuki suggested, theses can be useful in order to provide ExtLib IO compatibility without the need to add a dependency to IO module (that's one - the only ? - nice thing with objects, since their type are not module-bounds). If success, I'm planing also to add this for Enums. Regards, Nicolas Cannasse (** MLI **) class ['a,'b] o_input : ('a,'b) input -> object method read : 'a method nread : int -> 'b method pos : int method available : int option method close : unit end class ['a,'b,'c] o_output : ('a,'b,'c) output -> object method write : 'a -> unit method nwrite : 'b -> unit method pos : int method flush : unit method close : 'c end val from_in : ('a,'b) #o_input -> ('a,'b) input val from_out : ('a,'b,'c) #o_output -> ('a,'b,'c) output (** ML **) class ['a,'b] o_input (ch:('a,'b) input) = object method read = read ch method nread n = nread ch n method pos = pos_in ch method available = available ch method close = close_in ch end class ['a,'b,'c] o_output (ch:('a,'b,'c) output) = object method write x = write ch x method nwrite x = nwrite ch x method pos = pos_out ch method flush = flush ch method close = close_out ch end let from_in ch = create_in ~read:(fun () -> ch#read) ~nread:ch#nread ~pos:(fun () -> ch#pos) ~available:(fun () -> ch#available) ~close:(fun () -> ch#close) let from_out ch = create_out ~write:ch#write ~nwrite:ch#nwrite ~pos:(fun () -> ch#pos) ~flush:(fun () -> ch#flush) ~close:(fun () -> ch#close) |