Browse thread
[Caml-list] Observations on OCaml vs. Haskell
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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
least:
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).
Rich.
--
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?"'