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 VAA10284; Mon, 3 Mar 2003 21:10:51 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA10676 for ; Mon, 3 Mar 2003 21:10:49 +0100 (MET) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id h23KAlT28960 for ; Mon, 3 Mar 2003 21:10:48 +0100 (MET) Received: (qmail 29843 invoked by uid 36130); 3 Mar 2003 20:10:45 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 3 Mar 2003 20:10:45 -0000 Date: Mon, 3 Mar 2003 12:10:45 -0800 (PST) From: brogoff@speakeasy.net To: Oliver Bandel cc: "caml-list@inria.fr" Subject: Re: [oliver: Re: [Caml-list] Strings as arrays or lists...] In-Reply-To: <20030303182806.GC624@first.in-berlin.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 oliver:01 caml-list:01 bandel:01 abstraction:01 char:01 erlang:01 agitate:01 extensional:01 notations:01 recursions:01 ocaml's:01 wjh:99 implemented:01 intuitively:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 3 Mar 2003, Oliver Bandel wrote: > What is an abstraction inversion? > Sounds very interesting, but I don't understand, waht this means. I'm abusing the term a bit, as I understand it. I'm pretty sure it comes from the Ada community. Roughly, it refers to implementing a low level abstraction on top of a higher level abstraction. In this case, I was using it as "representing an efficient abstraction on top of an inefficient one", as I claim you would have to do if you try to build strings on top of char lists. (PS: you can try using Google, www.google.com, or another search engine, when you se a term you don't understand) (PPS: someone reminded me that Erlang also botched strings) > What I first have written about the string-stuff, > was: It's not FP-like, but I also would be happy > with a syntax, that would allow me, to use Array-functions > for the Strings. That's why I said "Agitate for extensional polyorphism!". You really want a way to overload similar notations. As you must now know, OCaml has no overloading. Extensional polymorphism gives you that overloading, on top of ML, in a way that even people who hate overloading should find fairly nonthreatening. Incidentally, I think substrings are the right FP-like way to handle strings. Substring operations are recursions on integer indices, and you can build them on top of OCaml's string type by adding two indices to a string. see either the SML Basis Library, or http://www-2.cs.cmu.edu/~wjh/publications.html#Hans1992a > If there maybe is a typing-reason, why not strings AND > arrays should have same syntax > ( e.g. both .[index] or both .(index) ) > then maybe it would be possible to add the typical > Array-functions (or List-functions) to the String-Library? > > Why not converting a string to a list with > String.to_list St. Xavier has rightly declared that blasphemous, and I've already done penance for showing it to you. I'm typing with my left hand, as all of the fingers on my right are broken. More seriously, I'm having a hard time coming up with realistic programming scenarios in which treating a string as a list is "the right thing". And while it is easy enough to convert using explode and implode, having it in the standard library would encourage bone headed programming. No one can stop you from doing it, but no one should help you do it, either. > or to an array with > String.to_array Strings are already array-like, and, even better, they are packed. > Arrays can be converted with Array.to_list (or vice versa > with Array.of_list). Why not such stuff for strings? > If they are already array-like, why not using such > functions? > > Why not using a String.map for application of > char-based functions to each char? The only time I ever want to map to a string is when I'm uppercasing or lowercasing. Those are already there! > To write more abstract String-manipulation is also ok, > so that the char-wise stuff would be on a lower level > (inside the library, maybe implemented in C or is some > imperative Ocaml-stuff, which the user of the library does not > see). > > OK, strings are not char-lists, and they are not char-arrays. > At least not to the user. > > > But it would help, to have such powerful functions like > > .map > .iter > .fold_left > .fold_right > .filter > > Where Module here would be one of: Array, List, String. Not for me. There are similarities between strings and arrays (more generally, random access sequences) of characters, but strings are such an important special case that they deserve their own library. Intuitively, lists and arrays are containers of things, but strings are not. Anyways, that's my story, and I'm sticking to it. If you don't like it, you know where to find Haskell! ;-) -- 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