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: [oliver: Re: [Caml-list] Strings as arrays or lists...]
Date: Mon, 3 Mar 2003 12:10:45 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0303031135560.9492-100000@grace.speakeasy.net> (raw)
In-Reply-To: <20030303182806.GC624@first.in-berlin.de>

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 <name>.[index]  or both <name>.(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
> 
> <Module>.map
> <Module>.iter
> <Module>.fold_left
> <Module>.fold_right
> <Module>.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


  reply	other threads:[~2003-03-03 20:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-03 18:28 Oliver Bandel
2003-03-03 20:10 ` brogoff [this message]
2003-03-03 21:05   ` William Lovas
2003-03-03 21:32     ` Basile STARYNKEVITCH
2003-03-03 22:10     ` [Caml-list] [RANT] String representation (was: Strings as arrays or lists...) Nicolas George
2003-03-04 12:43       ` Diego Olivier Fernandez Pons
2003-03-04 16:14         ` William D. Neumann
2003-03-04 18:38           ` Xavier Leroy
2003-03-04 18:50             ` William D. Neumann
2003-03-04 19:01         ` Nicolas George
     [not found]       ` <Pine.A41.4.44.0303041312560.4431978-100000@ibm1.cicrp.juss ieu.fr>
2003-03-04 13:49         ` David Chase
2003-03-04  0:20     ` [oliver: Re: [Caml-list] Strings as arrays or lists...] Issac Trotts
2003-03-04  0:24       ` Alain.Frisch
2003-03-04  1:06         ` Issac Trotts
2003-03-04  0:39       ` Olivier Andrieu
2003-03-04  0:39     ` brogoff
2003-03-03 21:40   ` [Caml-list] extensional polymorphism james woodyatt
2003-03-04  1:10     ` brogoff
2003-03-04  2:04       ` james woodyatt

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.0303031135560.9492-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).