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
Re: [Caml-list] Pattern matching and strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-04 (19:28)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Pattern matching and strings

Luc Maranget wrote:

> I have thought about that a little.
> My first guess is that such matching should be distinct from
> ordinary PM, mixing the two would be an implementor nightmare.
> My second guess is that what you want is regexp matching + a construct
> for binding subparts of the matched string (maybe I am wrong here).
> Using ocamllex syntax for patterns (+ as) your exemple could be written
> regexpmatch s with
> | "foo" (_* as x)  -> foo x
> | "bar" (_* as x)  -> bar x
> | _*               -> raise Unrecognized

This is basically what I was looking for.

> This would be much nicer than using various regexp packages API, the
> real add-on being the variables in place of \1, \2 etc.


> ...
> In fact such, an extension is probably feasible using camlp4 and this
> would probably be the best solution, to avoid extra-complexity in the
> compiler itself.

I really must get around to learning Camlp4. Why did no one 
teach it to me when I was at the X?

> In the end, do not hold your breath. I won't probably do that.
> But it can be a interesting project for a compiler course...
> --Luc



To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: