Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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-29 (15:58)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Re: Common IO structure
On Thu, Apr 29, 2004 at 04:46:49PM +0100, Benjamin Geer wrote:
> The key for me is that I need to be able to chain processing steps 
> together, so that I can, for example, decompress gzip format and convert 
> the result to Unicode, a few bytes at a time.  This suggests to me that 
> the gzip compressor and the Unicode processor should themselves be 
> implementations of the standard File object, so I can wrap a gzip 
> decompressor around an underlying data source, then wrap the Unicode 
> decoder around the gzip decompressor.  The advantage of this approach is 
> that the Unicode decoder doesn't know it's dealing with a gzip 
> decompressor; it only knows it's dealing with something it can read 
> bytes from.  I can then easily remove the decompression step if needed. 

I entirely agree that this is needed.  My focus however was on making
it simple to do the common things, and possible to do the rare, hard
stuff.  So the API designer should start by writing example programs
in the non-existant API.  Here are some rather fuzzy ideas of mine:

open IO

(* Read a whole file. *)
let content = slurp filename;;

(* Get a list of lines from a compressed file. *)
let lines = open filename >> unzip >> slurp_lines;;

(* Call function f line-by-line on a UTF-16 encoded file. *)
open filename >> utf16_decode >> slurp_lines >> (List.iter f);;

There are some obvious problems (eg. how are files closed? is '>>' a
reserved operator already?) but it's nice to think about what an easy
to use API might look like first *before* thinking about the


Richard Jones.
Merjis Ltd. - improving website return on investment
Learning Objective CAML for C, C++, Perl and Java programmers:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: