caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <lists@philippewang.info>
To: Till Varoquaux <till.varoquaux@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] About the O'Reilly book on the web
Date: Wed, 29 Nov 2006 00:07:34 +0100	[thread overview]
Message-ID: <456CC136.4080905@philippewang.info> (raw)
In-Reply-To: <9d3ec8300611281433q5509ccby65937fd4384f5a25@mail.gmail.com>

Hello,

> Although I do agree the problem seems a little more complicated:
> we are used to a more or less standard regexp syntax where special
> chars can be escaped by \, this obviously clashes with escaping
> characters in string if we pass strings to the function defining the
> regular exceptions....
> I would recommend treating all warnings as errors:
> -warn-error A
> to avoid such conflicts.

I am not used to using regexp with Caml... (although I write some 
scripts with OCaml instead of using Bash or Perl, or even Php, sometimes...)
But writing systematically the double backslash for a single regexp 
backslash and a quadruple backslash for a backslashed backslash... Well 
I wouldn't do it!


> As far as I'm concerned I find the problem to be more complicated:
> regular expressions are not syntaxily checked nor are they typed
> checked when specified through strings. Some languages intergrate them
> as first class values  thus allowing these verifications.

Last semester, with some friends we wrote a Caml compiler (that keeps 
the type informations at runtime), and one idea (which we did not 
implement because of some lack of time) was first class regexp, a bit 
like in Perl, while mixing it with the match-with-like syntax... (If 
only we could have as much time as we want or need...)

It could be something "usable", like :

matchr (* the matchr keyword is an example *)
   "some string"
with
| "PLOP 42 - \([0-9]\)" -> Int (int_of_string $1)
| "PLOP 43 - \(.*\)" -> $1

Then you can close it like in Coq with an "end" keyword, or just keep 
the OCaml syntaxe... (implicit closing, whatever)

Well, of course, bad thing could be that $ is a character for infix 
operators (but whatever it's not so important)

Then the question is still "What do we want OCaml to be?"
Do we want to make regexps easy to use with OCaml ? And are we ready to 
make OCaml bigger ("just") for that ?

> Another
> solution would be to build them using an Ocaml recursive sum type.
> Although this would solve the syntax problem it would make regexp very
> tedious to write. A library offering both options can be found at:
> http://www.lri.fr/~marche/regexp/

It looks really ... "not funny" I would say!


> Ideally one would want to precompile regular expression from strings
> to actual constructed types using a preprocessor (e.g. camlp4). It
> seems Francois Potier was one of the first to try such an approach:
> [http://caml.inria.fr/pub/ml-archives/caml-list/2001/07/30b327c7c4b0fa5ace86dbf258e2c5d1.en.html] 
> 
> I'm pretty sure this has been done in other libraries (regexp-pp  for
> instance). Actual type-checking might prove a little harder to get
> working.

Actually I don't really see the types problems...
If everything in return with $n has type string, then there is no 
matter... We can also easily detect that $4 does not exist for a regexp 
such as "\(PLOP[4-2]\) 42.*" :-p
(or decide that $4 would be an empty string, but it would seem a bit dirty)

Anyways, it would probably be more "a good thing" than "a bad thing"...

Philippe

> P.S.:Je confirme: j'ai bien recu ton mail ;-)...

PS : Je n'ai toujours pas compris comment ça marche...
  Parce que le mail qui est passé est celui qui a été envoyé avec la 
mauvaise adresse o_O
  Peut-être que je comprendrai un jour prochain...
(donc je retente avec la "mauvaise adresse" puisque ça semble mieux 
fonctionner)


      parent reply	other threads:[~2006-11-28 23:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-25 18:38 Francois Colonna
2006-11-27  9:07 ` [Caml-list] " Sebastien Ferre
2006-11-28 21:01   ` Philippe Wang
2006-11-28 22:33     ` Till Varoquaux
2006-11-28 22:47       ` Martin Jambon
2006-11-29  0:18         ` Philippe Wang
2006-11-29  1:48           ` Martin Jambon
2006-11-29 15:26             ` Philippe Wang
2006-11-29 17:52             ` Diego Olivier FERNANDEZ PONS
2006-11-29 17:25           ` brogoff
2006-11-29 18:10             ` Philippe Wang
2006-11-30  2:30               ` skaller
2006-11-30 18:20                 ` Tom
2006-12-01  3:21                   ` skaller
2006-12-01  6:48                     ` Tom
2006-11-29 21:20             ` Jon Harrop
2006-11-29 21:25               ` Till Varoquaux
2006-12-01  0:12               ` brogoff
2006-11-28 23:07       ` Philippe Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=456CC136.4080905@philippewang.info \
    --to=lists@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=till.varoquaux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).