Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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.
Merjis Ltd. - 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?"'