caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff@speakeasy.net
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Strings as arrays or lists...
Date: Thu, 27 Feb 2003 17:03:07 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0302271639370.2764-100000@grace.speakeasy.net> (raw)
In-Reply-To: <20030227223155.GA488@first.in-berlin.de>

On Thu, 27 Feb 2003, Oliver Bandel wrote:
> Hello,
> 
> 
> in Haskell, strings are lists of chars.

And what a horrible design decision that is! Even the other 
lazy language (Clean) doesn't screw this one up, and last I looked 
at it had strings as unboxed character arrays. 

> In Ocaml, strings seem to be array-like,
> but it's not possible to apply Array-functions
> on Strings, but nevertheless, the char's of a
> string are used in a very similar way, as arrays.

Think of them as packed character arrays. 

> The indexing is done with .(idx) in the one case
> and with .[idx] in the other case.

OK, so some of us will be much happier if (when?) OCaml implements 
extensional polymorphism and we can treat all array like thingies uniformly. 

> Well, when strings would be lists of chars,
> List-commands like List.map and List.filter
> could be used.

Oh really? And what do we do when we want to use List.map on a long string? 
On my machine, Sys.max_string_length is 16_777_211. List.map will crap out 
on a much smaller list. 

> This would be more FPL-like. (And more convenient
> and IMHO more consistently.)

It would also be way slower, and restrict strings to much smaller lengths.
The length restriction can (and should!) be fixed by extending the set of 
functions which are tail recursive, as has been discussed on this list in 
the last month. However, I think array like representations for strings make 
more sense, and if "FPL" means "handles arrays poorly" then I think the flaw 
is in FPLs. 

> But even if only the imperative Array-access would
> be possible (instead of the FPL-like Lists), it would
> be more convenient then to have such a string-type,
> which can't be used with the many libraries.

I can't quite parse this, but if you mean that you'd like to treat strings 
like arrays notationally, I agree. Agitate for extensional polymorphism. 
Wow, that sounds even better than "eschew obfuscation"!

> Any suggestions on that topic?

There is no one string representation which will satisfy everyone. I prefer 
the built in one to be array based, like in OCaml. You can easily write a 
function like this 

let explode s =
  let rec exap n l =
    if n < 0 then l else
    exap (n - 1) ((String.get s n)::l) in
  exap (String.length s - 1) []

to get the char list you want. You couldn't get the packed char array from 
a char list if it wasn't built in. 

-- Brian


-------------------
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:[~2003-02-28  1:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-27 22:31 Oliver Bandel
2003-02-28  1:03 ` brogoff [this message]
2003-03-02 18:34   ` Xavier Leroy
2003-03-02 19:03     ` Alain.Frisch
2003-03-03  8:50     ` Luc Maranget
2003-03-03 17:12       ` brogoff
2003-03-03 17:40         ` Diego Olivier Fernandez Pons
2003-03-04  2:49     ` Eric C. Cooper
2003-03-04  8:29       ` Fabrice Le Fessant

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=Pine.LNX.4.44.0302271639370.2764-100000@grace.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /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).