Version française
Home     About     Download     Resources     Contact us    
Browse thread
[oliver: Re: [Caml-list] Strings as arrays or lists...]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas George <nicolas.george@e...>
Subject: [Caml-list] [RANT] String representation (was: Strings as arrays or lists...)
Le tridi 13 ventôse, an CCXI, William Lovas a écrit :
>     type string = char array

BTW, *this* is the worst conceptual bug in OCaml, directly imported from
the C. Strings and arrays are totally different concept.

- Strings need fast concatenation and parts extraction, arrays do not
  need that.

- Arrays need fast random access by numeric index, strings do not need
  that.

My dream for a future release of OCaml would be something like that:

- string is an abstract type, with fast concatenation (especially when
  one of the operands is not used anymore; this is like tail-recursion
  optimisation, but for strings);

- there is also a `cursor' type, which is something like a pair
  (string, index in that string);

- there are functions to move cursors forward and backward, take
  substrings between two cursors, etc.;

- while we're at breaking compatibility, strings are fully Unicode
  capable;

- there is a buffer type which is a byte array for low-level operations,
  and conversion functions between buffers and strings, with several
  possible encodings;

- there is a regular expression module with a syntax as near as perl's
  as possible (because perl's regexps are great, and we do not want to
  have to remember yet another regexps variant), which returns cursors
  for matched substrings.