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] Observations on OCaml vs. Haskell
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-28 (08:27)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Observations on OCaml vs. Haskell
On Mon, Sep 27, 2004 at 02:08:51PM -0500, John Goerzen wrote:
> It's annoying that strings aren't normally processed this way in OCaml, 
> and even more annoying that (^) or (::) cannot be used in pattern 
> matching over strings.

While having strings represented as lists of characters is a bad idea
for performance reasons, I don't see why we can't allow more advanced
pattern matching than simply just string equality.  I'd like to see at

  match str with
    "prefix" ^ rest -> ...

which is very useful when parsing up certain types of CGI query
strings, and even better would be full regexp support:

  match str with
    "^(.+)-(.+)$" as f, t
      -> printf "range: from '%s' to '%s'" f t
  | "^(.+)$" as v -> printf "singular: '%s'" v

(this example taken from Yutaka Oiwa's regexp syntax extension written
in camlp4).


Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
'There is a joke about American engineers and French engineers. The
American team brings a prototype to the French team. The French team's
response is: "Well, it works fine in practice; but how will it hold up
in theory?"'