English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] [ANN] The Missing Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-27 (23:32)
From: Gerd Stolpmann <info@g...>
Subject: Re: [Caml-list] Re: Common IO structure
On Die, 2004-04-27 at 21:08, Nicolas Cannasse wrote:
> >
> > http://ocamlnet.sourceforge.net/intro/netchannels.html
> We're actually quite near to agree on what should be the minimal
> requirements.
> Looks like you included pos_in / pos_out into the "fundamentals methods" ,
> would you agree to drop theses ?

I would not regard them as fundamental. Actually, they are derived, as
they only count the characters flowing through input/output. (They have
nothing to do with absolute file positions.)

Of course, I don't remove them from ocamlnet, as they are very useful
for that context. It is no problem to coerce them away, and to create
them when needed by inheriting them from a virtual class. That won't
complicate interoperability very much.

> In short, I think we all want different things :
> - Yamagata Yoriyuki want IO to be on a char basis (and that makes sense for
> Unicode)
> - you would prefer having buffered channels (and that make sense for network
> protocols, parsing, ...)

They can also be unbuffered, it is not specified. The nice thing about
ocamlnet's channels is that you can add buffers when you need them,
without changing the signature.

Of course, the focus are buffered channels.

> - I propose that we have two way of accessing the channel, that can be
> buffered or unbuffered, or others. I think this is enough general to cover a
> lot of different usage, and introduce some interesting polymorphism.
> I would like to get your opinion on that.

I guess you mean this one from a previous mail:

class ['a,'b] input = object
    method read : 'a
    method nread :  int -> 'b
    method close_in : unit

class ['a,'b,'c] output = object
    method write : 'a
    method nwrite : 'b
    method close_out : 'c

I doubt this is very practical. Consider you want to write Unicode
characters into a file (I think a common example). The file as such is a
byte stream, but you want an additional Unicode interface that converts
implicitly to, say UTF-8. With your idea of generalised channel, the
only way to do this is to build layers, something like

let file_as_byte_channel = new file_out_channel "name" in
let file_as_uni_channel = new convert_utf8_to_byte file_as_byte_channel

Call file_as_byte_channel # write to output a byte, and call
file_as_uni_channel # write to output a Unicode character. You don't
have a single object that can do both, however. Even worse: If you want
to use both interfaces alternately, you have to be careful to flush
buffers at the right time (in the case there are buffers).

I think it is better to have two methods, one for the polymorphic case,
and one for strings. The latter plays a special role, simply because all
I/O finally is string I/O.

Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners