Re: [Caml-list] pattern matching on strings

2011-09-17 Thread Philippe Veber
Thank you Raphael ! Indeed, keeping the C encoding underneath strings (and arrays) is a nice property. ph. 2011/9/14 Raphael Proust > Richard Jones described the internals of OCaml quite concisely. The > difference between char arrays and strings is exposed in part two of > his series of posts:

Re: [Caml-list] pattern matching on strings

2011-09-17 Thread Basile Starynkevitch
On Fri, 16 Sep 2011 22:20:05 +0100 "Richard W.M. Jones" wrote: > On Wed, Sep 14, 2011 at 10:40:11PM +0200, Basile Starynkevitch wrote: > > And there is a reason why you cannot match (in Ocaml) on the content > > of strings (or arrays). It won't be easy to implement efficiently > > (you would need

Re: [Caml-list] pattern matching on strings

2011-09-16 Thread Richard W.M. Jones
On Wed, Sep 14, 2011 at 10:40:11PM +0200, Basile Starynkevitch wrote: > And there is a reason why you cannot match (in Ocaml) on the content > of strings (or arrays). It won't be easy to implement efficiently > (you would need to copy a substring or subarray when matching) How about just prefix ma

Re: [Caml-list] pattern matching on strings

2011-09-14 Thread Raphael Proust
Richard Jones described the internals of OCaml quite concisely. The difference between char arrays and strings is exposed in part two of his series of posts: https://rwmj.wordpress.com/2009/08/05/ocaml-internals-part-2-strings-and-other-types/ There is a pointer to http://caml.inria.fr/pub/ml-arch

Re: [Caml-list] pattern matching on strings

2011-09-14 Thread Philippe Strauss
It reminds me of the micmatch/mikmatch project(s), http://martin.jambon.free.fr/micmatch.html, but never used it, only remember reading the announce on the hump or this list. Le 14 sept. 2011 à 22:16, Walter Cazzola a écrit : > Hi all, > I'm just trying to write a recursive function that iterat

Re: [Caml-list] pattern matching on strings

2011-09-14 Thread Philippe Veber
Hi Walter, Contrary to Prolog or Haskell, strings in ocaml are not represented as char lists. They are exactly like char array, but have their own type, operations and syntax : strings are created with String.make (similar to Array.make), their length is given by String.length (sim. to Array.lengt

Re: [Caml-list] pattern matching on strings

2011-09-14 Thread Basile Starynkevitch
On Wed, 14 Sep 2011 22:16:42 +0200 (CEST) Walter Cazzola wrote: > > Does this mean that I can't write a function on strings by pattern > matching or is there something I don't know? No, standard Ocaml 3.12 has no way of doing matching (in the sense of the match expression) on [the content of] Oc

[Caml-list] pattern matching on strings

2011-09-14 Thread Walter Cazzola
Hi all, I'm just trying to write a recursive function that iterates¹ on a string and I'd like to use pattern matching as in: let rec iter f s = match s with | "" -> unit; | c^s1 -> f c; iter f s1;; but the ^ concatenates 2 strings and not a char with a string and above all seems to