English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] unix.chop_extension
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-27 (17:29)
From: brogoff <brogoff@s...>
Subject: Re: [Caml-list] unix.chop_extension
On Wed, 26 May 2004, Richard Jones wrote:
> On Wed, May 26, 2004 at 01:21:01PM +0200, Alex Baretta wrote:
> > Actually, I'm a happy user of Str, but I find the absence in Ocaml of a
> > functional "canonical" regexp feature striking.
> I'm fascinated to know what this "functional" API would look like.  I
> use Pcre and it doesn't appear to have any global internal state
> AFAICS ...

As you note, the interface to Pcre, unlike Str, appears stateless.

If you examine some functional data structure libraries, like Martin Erwig's
FGL, or Gerard Huet's ZEN, you notice that they use the idea of "location +
context" (similar to the C++ STL, where the locations are iterators)  to
navigate the structure. For string processing, the context is the entire string,
and the location is the pair of endpoints of the current string. So it seems
that the right way to a functional API for string processing would be in terms
of substrings, { base : string; left : int; right : int } or just
string * int * int, which is what is done in the SML Basis. The idea extends
naturally to regexp scanning, and it's easy to see how to modify the Str
interface to use substrings, eliminating Not_found exceptions by considering
an empty substring to be a failed match.

Of course, substrings make sense when the underlying string is array like, not
in FPLs like Haskell which use lists of chars as strings, but I consider that an
egregious error of 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