From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA29440; Fri, 28 Feb 2003 02:03:11 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA28752 for ; Fri, 28 Feb 2003 02:03:10 +0100 (MET) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h1S139H24161 for ; Fri, 28 Feb 2003 02:03:09 +0100 (MET) Received: (qmail 29894 invoked by uid 36130); 28 Feb 2003 01:03:07 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 28 Feb 2003 01:03:07 -0000 Date: Thu, 27 Feb 2003 17:03:07 -0800 (PST) From: brogoff@speakeasy.net To: Oliver Bandel cc: "caml-list@inria.fr" Subject: Re: [Caml-list] Strings as arrays or lists... In-Reply-To: <20030227223155.GA488@first.in-berlin.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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