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
Re: [Caml-list] Strings as arrays or lists...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-03 (17:12)
From: brogoff@s...
Subject: Re: [Caml-list] Strings as arrays or lists...
Yes, Xavier is right here, and I apologize for posting an "explode" function 
on this list. I'll appeal for leniency, mentioning that I didn't post 
"implode", and that I only posted the former function to demonstrate that 
it could be done, and to point out that one of the many reasons strings as 
char lists is wrong as a basic type is that you get an abstraction inversion. 

As far as char lists being somewhat advantageous in a lazy language, well, I 
won't start a flamewar as to whether laziness as the default is a good design 
decision (oh hell, I'll admit, I think it isn't) but I'll repeat my 
observation that in the Clean language, also lazy by default like Haskell, 
strings are unboxed character arrays. 

Back to the topic which interests us, OCaml. One thing I'd like to see in an 
extended library is a fairly rich substring library, perhaps like the one in 
the SML Basis. I have the beginnings of one, and I also ported the SML one 
from Moscow ML to OCaml. It can certainly be made richer, the first improvement 
on my list being an integration with a regexp package. 

I'm sure there are numerous ideas just for string libraries, and that we could 
fill an entire mailing list just with those. Ropes (a binary tree representation 
for applicative "big strings") and extended character sets (I guess Camomile is 
doing that now?) are my favorites. 

-- Brian

On Mon, 3 Mar 2003, Luc Maranget wrote:
> > > > in Haskell, strings are lists of chars.
> > > 
> > > And what a horrible design decision that is!
> > 
> > Agreed.  Well, it's a great way to multiply the memory requirements
> > for your strings by a factor of 12 (on 32-bit platforms) or 24 (on
> > 64-bit platforms), while at the same time losing constant-time
> > indexing :-)  
> > 
> > Actually, the list representation of strings is so repugnant that I
> > don't even want to include "explode" and "implode" coercions between
> > string and char list in the standard library.  A standard library
> > should steer users away from algorithmically-inefficient code.  By not
> > having implode and explode in the library, I hope OCaml programmers
> > will come to the realization that the proper way to operate on strings
> > is either via block operations (the String module, regexps, etc), or
> > by recursion on integer indices.
> > 
> > - Xavier Leroy
> > 
> Xavier is right, of course.
> However, in a lazy context, seeing strings as list of chars has some
> advantages. This is not relevant to Caml anyway.
> --Luc
> -------------------
> To unsubscribe, mail Archives:
> Bug reports: FAQ:
> Beginner's list:

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