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