caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Cannasse" <warplayer@free.fr>
To: "Yamagata Yoriyuki" <yoriyuki@mbg.ocn.ne.jp>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: Common IO structure
Date: Tue, 27 Apr 2004 18:17:32 +0200	[thread overview]
Message-ID: <016501c42c73$24e64b30$ef01a8c0@warp> (raw)
In-Reply-To: <20040428.004358.45522587.yoriyuki@mbg.ocn.ne.jp>

> > So ? That's exactly what we're talking about it there : making a choice.
And
> > that include naming of course. I don't say that the name we choosed for
> > ExtLib IO are better, it's just that "reading" and "writing" on an IO
seems
> > natural to me.
>
> get/put are used in Camomie already, and input/output are used in
> ocamlnet.  OO wrappers of Extlib IO are only recent addition, so
> changing Extlib is more natural.  In this case, what Extlib should do is
> just changing OO wrappers.  I do not think you need to change IO
> module itself.

As someone told, read/write concepts are used in most of other languages
(including Java, C, and many others). I agree ExtLib's IO are recent and
should not dictate how other libraries methods should be named. But since
we're standardizing things, Camomile , Ocamlnet and Extlib will have all to
rewrite some code in order to be intercompatible. Since we need to do that,
let's make a choice not based on what's already written, but on what's is
best for the end user. A slashdot poll would help here :)
But don't worry, if you and Gerd agree on some naming, ExtLib IO will
follow. I just want that the read/write naming be taken care as much as
other naming possibilities.

> > > Another problem is that it is not minimal
> > > enough.  For character converters, it is impossible to predict how
> > > many characters will be available, for example.  And requiring "pos",
> > > "nread", "nwrite" seems arbitrary for me.  They are somtimes useful
> > > and improvement, but not necessary.
> >
> > That's true, I agree with you but on the last point : they are necessary
in
> > order to get good performances. Concerning "available", it returns None
if
> > no data available. "pos" might throw an exception as well when
unavailable
> > (looks like pos and available should have same behavior here).
>
> My philosophy is to make the type informative as far as possible.  If
> some method does not work, I would rather remove the method, and
> notify this fact to a user in the compile time (not in the runtime).  A
> user, or the library developer can provide wrappers if necessary.
>
> Philoshophy aside, I do not see how pos and available improve
> performance.  pos certainly decreases performance.  Anyways disks are
> much slower than CPU, so arguing small performance benefit is
> nonsense.  Since there are many possible "improvements" (seek, unget,
> length, destination addresses), it would be better to stick the
> algebraically minimal specification.
>
> Note that I do not oppose extension as such.  I oppose making them as
> the standard.


I agree on dropping pos and available from the standard. ExtLib will deal
consistenly without them.


> > And nread/nwrite can simply call n times read/write. That means that
> > any library can put default implementation for additional "not
> > minimal" constructs : they will behave poorly (writing a string char
> > by char) but will interface well with other IO that are supporting
> > them correctly. If implementing efficently nread/nwrite require
> > additionnal effort, then let's implement a default behavior and
> > implement it better later. Having theses functions make room for
> > future improvements, which is not done with minimal IO.
>
> Choosing a type of buffers is not trivial (except char, in this case I
> propose using stirng, of courst).  For exmaple, what is for a Unicode
> channel?  UTF8/UTF16/UTF32 strings, array, DynArray.t, all have their
> own advantage.  And if someone uses UTF8, another uses UTF16 and so
> on, then there is not much point of having standard.
>
> Of course we would make "nread/nwrite" use a default buffer type
> (maybe list, as you do Extlib), but I doubt that such "filler" methods
> do any good.

They'll maybe not - in the Unicode case, but they'll definilty help for
other IO.
Concerning the channels, I'm against having 4 classes instead of 2. If the
user need to write both chars and strings, he will need to carry two objects
instead of one.
My proposal is based on the following :

class input = object
     method read : char
     method nread  : int -> string
     method close_in : unit
end

class output = object
     method write : char
     method nwrite : string
     method close_out : unit
end

and since it's so easy, let's add some polymorphism to get more general and
more powerful IO objects :

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

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

Having bi-polymorphism over an IO is really powerful : you can handle
buffered read/write like this or polymorphic writes (two ways of reading,
two ways of writing).
An example from the ExtLib :

val input_bits : (char,'a) input -> (bool,int) input
val output_bits : (char,'a,'b) output -> (bool,(int * int),'b) output

enable you to read bit-by-bit over a channel :

let ch = input_bits .... in
let b = IO.read ch in (* read a bit as a boolean *)
let n = IO.nread ch 5 in (* read 5 bits as an integer *)
...

let ch = output_bits ... in
IO.write ch true; (* write a bit *)
IO.write ch false;
IO.nwrite ch (5,31); (* write 31 using 5 bits *)

It's not only an extension : putting that in the core interface enable a
wide kind of IO.
I'm interested in your thinking about that.

Best Regards,
Nicolas Cannasse

-------------------
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


  reply	other threads:[~2004-04-27 16:18 UTC|newest]

Thread overview: 210+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-23 18:51 [Caml-list] [ANN] The Missing Library John Goerzen
2004-04-23 19:52 ` Kenneth Knowles
2004-04-23 20:09   ` Alexander V. Voinov
2004-04-23 20:27     ` John Goerzen
2004-04-23 20:23   ` John Goerzen
2004-04-23 20:36     ` Maxence Guesdon
2004-04-23 21:10       ` John Goerzen
2004-04-23 21:12         ` Maxence Guesdon
2004-04-23 21:18           ` Maxence Guesdon
2004-04-23 21:32             ` Nicolas Cannasse
2004-04-23 21:46             ` John Goerzen
2004-04-23 21:58               ` Maxence Guesdon
2004-04-24  8:15                 ` Matthieu BRUCHER
2004-04-24  8:15                   ` Maxence Guesdon
2004-04-23 21:36           ` John Goerzen
2004-04-23 21:33         ` John Goerzen
2004-04-23 22:04           ` Alain.Frisch
2004-04-24  4:26             ` John Goerzen
2004-04-24  8:13               ` Alain.Frisch
2004-04-24  9:28                 ` Nicolas Cannasse
2004-04-25  8:56                   ` Common IO structure (was Re: [Caml-list] [ANN] The Missing Library) Yamagata Yoriyuki
2004-04-25 11:54                     ` Gerd Stolpmann
2004-04-26 14:53                       ` [Caml-list] Re: Common IO structure Yamagata Yoriyuki
2004-04-26 21:02                         ` Gerd Stolpmann
2004-04-25 19:42                     ` Common IO structure (was Re: [Caml-list] [ANN] The Missing Library) Nicolas Cannasse
2004-04-26 13:16                       ` [Caml-list] Re: Common IO structure Yamagata Yoriyuki
2004-04-26 13:53                         ` Jacques GARRIGUE
2004-04-26 14:26                           ` Nicolas Cannasse
2004-04-28  6:52                             ` Jacques GARRIGUE
2004-04-26 14:23                         ` Nicolas Cannasse
2004-04-26 14:55                           ` skaller
2004-04-26 15:26                           ` Yamagata Yoriyuki
2004-04-26 19:28                             ` Nicolas Cannasse
2004-04-26 20:56                               ` Gerd Stolpmann
2004-04-26 21:14                                 ` John Goerzen
2004-04-26 22:32                                   ` Gerd Stolpmann
2004-04-26 21:52                                 ` Benjamin Geer
2004-04-27 16:00                                 ` Yamagata Yoriyuki
2004-04-27 21:51                                   ` Gerd Stolpmann
2004-04-27 19:08                                 ` Nicolas Cannasse
2004-04-27 22:22                                   ` Gerd Stolpmann
2004-04-28  7:42                                     ` Nicolas Cannasse
2004-04-29 10:13                                   ` Yamagata Yoriyuki
2004-04-27 15:43                               ` Yamagata Yoriyuki
2004-04-27 16:17                                 ` Nicolas Cannasse [this message]
2004-04-27 16:58                                   ` Yamagata Yoriyuki
2004-04-27 23:35                                     ` Benjamin Geer
2004-04-28  3:44                                       ` John Goerzen
2004-04-28 13:01                                         ` Richard Jones
2004-04-28 21:30                                         ` Benjamin Geer
2004-04-28 21:44                                           ` John Goerzen
2004-04-28 22:41                                             ` Richard Jones
2004-04-29 11:51                                               ` Benjamin Geer
2004-04-29 12:03                                                 ` Richard Jones
2004-04-29 15:16                                                   ` Benjamin Geer
2004-04-29 10:27                                             ` Yamagata Yoriyuki
2004-04-29 13:03                                               ` John Goerzen
2004-04-29 13:40                                                 ` Yamagata Yoriyuki
2004-04-29 14:02                                                   ` John Goerzen
2004-04-29 15:31                                                     ` Yamagata Yoriyuki
2004-04-29 17:31                                                       ` james woodyatt
2004-04-29 23:53                                                         ` Benjamin Geer
2004-04-30  4:10                                                           ` james woodyatt
2004-04-29 11:23                                             ` Benjamin Geer
2004-04-29 12:23                                               ` Richard Jones
2004-04-29 15:10                                                 ` Benjamin Geer
2004-04-29 15:35                                                   ` John Goerzen
2004-04-29 15:46                                                     ` Benjamin Geer
2004-04-29 15:58                                                       ` Richard Jones
2004-04-29 20:41                                                       ` John Goerzen
2004-04-29 22:35                                                         ` Benjamin Geer
2004-05-01 14:37                                                 ` Brian Hurt
2004-04-29 13:23                                               ` John Goerzen
2004-04-29 14:12                                                 ` John Goerzen
2004-04-29 15:37                                                 ` Benjamin Geer
2004-04-28  7:05                                       ` Nicolas Cannasse
2004-04-28  0:20                                     ` skaller
2004-04-28  3:39                                     ` John Goerzen
2004-04-28 13:04                                     ` Richard Jones
2004-04-24  9:40               ` [Caml-list] [ANN] The Missing Library Oliver Bandel
2004-04-23 22:54           ` Henri DF
2004-04-23 23:11           ` Shawn Wagner
2004-04-25  6:55           ` james woodyatt
2004-04-25  7:56             ` Brandon J. Van Every
2004-04-25 11:50             ` Benjamin Geer
2004-04-25 13:55               ` skaller
2004-04-26 12:08                 ` Martin Berger
2004-04-26 12:51                   ` skaller
2004-04-26 14:49                   ` skaller
2004-04-28  4:31                   ` Brian Hurt
2004-04-28  5:13                     ` Jon Harrop
2004-04-28  8:37                       ` skaller
2004-04-28  9:18                         ` Jon Harrop
2004-04-28 11:24                           ` skaller
2004-04-28 15:18                             ` John Goerzen
2004-04-28 16:28                               ` skaller
2004-04-28 18:02                                 ` John Goerzen
2004-04-29  0:54                                   ` skaller
2004-04-29 11:57                                     ` Andreas Rossberg
2004-04-29 13:38                                     ` John Goerzen
2004-04-28 18:42                                 ` Jon Harrop
2004-04-29  1:03                                   ` skaller
2004-04-29  1:56                                     ` Jon Harrop
2004-04-29  2:35                                       ` skaller
2004-04-29  3:00                                       ` skaller
2004-04-29  5:04                                         ` Jon Harrop
2004-04-29  5:38                                           ` skaller
2004-04-29  5:47                                     ` james woodyatt
2004-04-29 12:05                                     ` Andreas Rossberg
2004-04-28 17:07                             ` james woodyatt
2004-04-28 17:31                               ` skaller
2004-05-03  0:02                                 ` Marcin 'Qrczak' Kowalczyk
2004-05-03  7:54                                   ` skaller
2004-05-03  8:58                                     ` Marcin 'Qrczak' Kowalczyk
2004-05-03 10:58                                       ` skaller
2004-05-03 12:40                                         ` Marcin 'Qrczak' Kowalczyk
2004-05-03 13:04                                           ` Nicolas Cannasse
2004-05-03 14:24                                           ` brogoff
2004-05-03 15:26                                             ` Marcin 'Qrczak' Kowalczyk
2004-05-03 15:08                                           ` skaller
2004-05-03 16:00                                             ` Marcin 'Qrczak' Kowalczyk
2004-05-03 11:32                                       ` [Caml-list] Re: Tail-calls in C code (was: [ANN] The Missing Library) Wolfgang Lux
2004-05-03 12:34                                         ` skaller
2004-05-03 12:38                                         ` skaller
2004-05-03 12:55                                           ` skaller
2004-05-03 13:02                                         ` Marcin 'Qrczak' Kowalczyk
2004-04-28 15:15                       ` [Caml-list] [ANN] The Missing Library John Goerzen
2004-04-28 20:43                         ` Jon Harrop
2004-04-30 15:58                       ` Brian Hurt
2004-05-01  2:48                         ` skaller
2004-04-28  8:24                     ` skaller
2004-04-28  8:42                       ` Martin Berger
2004-04-28 11:38                         ` skaller
2004-04-28 16:07                           ` [Caml-list] " Shivkumar Chandrasekaran
2004-04-28 11:31                       ` [Caml-list] " Yaron M. Minsky
2004-04-28 12:09                         ` skaller
2004-04-28 12:36                           ` Nicolas Cannasse
2004-04-28 13:39                             ` skaller
2004-04-28 14:02                               ` Nicolas Cannasse
2004-04-28 15:34                                 ` skaller
2004-04-28 13:15                           ` Jean-Christophe Filliatre
2004-04-28 14:31                             ` skaller
2004-04-28 14:40                               ` Jean-Christophe Filliatre
2004-04-28 15:51                                 ` skaller
2004-04-28 13:29                           ` Andreas Rossberg
2004-04-28 16:10                           ` [Caml-list] " Shivkumar Chandrasekaran
2004-04-28 17:14                             ` skaller
2004-04-28 17:34                               ` Shivkumar Chandrasekaran
2004-04-28 20:00                               ` Jon Harrop
2004-04-25 12:20             ` [Caml-list] " Benjamin Geer
2004-04-25 14:06               ` skaller
2004-04-25 15:07                 ` Benjamin Geer
2004-04-26  0:19                   ` skaller
2004-04-23 22:08         ` Basile STARYNKEVITCH
2004-04-24  4:40           ` John Goerzen
2004-04-24 10:10           ` Oliver Bandel
2004-04-24 19:31             ` skaller
2004-04-23 20:54     ` Kenneth Knowles
2004-04-23 21:07       ` John Goerzen
2004-04-25 15:43       ` Brian Hurt
2004-04-26  0:22         ` skaller
2004-04-28  4:10           ` Brian Hurt
2004-04-26  6:48     ` Florian Hars
2004-04-23 20:41 ` Eric C. Cooper
2004-04-23 21:16   ` John Goerzen
2004-04-23 22:28     ` Shawn Wagner
2004-04-23 22:37       ` Kenneth Knowles
2004-04-23 23:16         ` Shawn Wagner
2004-04-24  1:38           ` [Caml-list] ocamlopt -pack portability John Carr
2004-04-24 10:31             ` Oliver Bandel
2004-04-24 16:53               ` John Carr
2004-04-24  4:46         ` [Caml-list] [ANN] The Missing Library John Goerzen
2004-04-24  2:43       ` Yamagata Yoriyuki
2004-04-24  9:19         ` Nicolas Cannasse
2004-04-24 12:27           ` Shawn Wagner
2004-04-24 12:58             ` Alain.Frisch
2004-04-24 17:36               ` Nicolas Cannasse
2004-04-26 14:49               ` Florian Hars
2004-04-24  2:44       ` Yamagata Yoriyuki
2004-04-24  4:51       ` John Goerzen
2004-04-24  5:11         ` Jon Harrop
2004-04-24 12:59       ` Proposal: community standard library project (was: Re: [Caml-list] [ANN] The Missing Library) Benjamin Geer
2004-04-24 17:29         ` [Caml-list] RE: Proposal: community standard library project Brandon J. Van Every
2004-04-24 18:23           ` Benjamin Geer
2004-04-25  4:37             ` Brandon J. Van Every
2004-04-26  1:45         ` [Caml-list] " Jacques GARRIGUE
2004-04-26  3:03           ` Brandon J. Van Every
2004-04-26  7:43           ` Martin Jambon
2004-04-26 18:25           ` Benjamin Geer
2004-04-26 19:37             ` Gerd Stolpmann
2004-04-26 20:24               ` skaller
2004-04-26 20:39                 ` John Goerzen
2004-04-26 22:17                   ` Brandon J. Van Every
2004-04-27  9:06                   ` skaller
2004-04-27  9:35                     ` Alain.Frisch
2004-04-27 11:29                     ` Gerd Stolpmann
2004-04-27 12:52                       ` skaller
2004-04-27 18:13                       ` [Caml-list] CVS labeling (was Re: Proposal: community standard library project) Brandon J. Van Every
2004-04-27 18:53                         ` John Goerzen
2004-05-03  6:12 [Caml-list] Re: Common IO structure Vladimir N. Silyaev
2004-05-04 21:31 ` Benjamin Geer
2004-05-04 22:59   ` Yamagata Yoriyuki
2004-05-05  8:11     ` skaller
2004-05-05 15:48       ` Marcin 'Qrczak' Kowalczyk
2004-05-05 19:28         ` skaller
2004-05-05 17:33     ` Vladimir N. Silyaev
2004-05-05 17:31   ` Vladimir N. Silyaev
2004-05-07 22:11     ` Benjamin Geer
2004-05-08  7:29       ` Vladimir N. Silyaev
2004-05-09 17:35         ` Benjamin Geer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='016501c42c73$24e64b30$ef01a8c0@warp' \
    --to=warplayer@free.fr \
    --cc=caml-list@inria.fr \
    --cc=yoriyuki@mbg.ocn.ne.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).