caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: Luc Maranget <luc.maranget@inria.fr>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Pattern matching and strings (and a mini-bug in Scanf)
Date: Wed, 02 Oct 2002 18:21:08 +0200	[thread overview]
Message-ID: <3D9B1CF4.5030706@baretta.com> (raw)
In-Reply-To: <200210021502.RAA0000000423@beaune.inria.fr>


Luc Maranget wrote:
> Hum, I am not found of such an idea. As you tell yoursef,  ``(^)  is
> an operator rather than a  constructor''. Making a special case for
> (^) is a bad idea from the start.
> The special thing about a pattern is that is contains constructors,
> variables, (and constants) and nothing else.
> This restriction allows efficient
> compilation and lots of static checks in some uniform framework.
> Getting out of the uniform framework is a risk
> (cf. n+k patterns in Haskell eg).

I realize this, but I also believe that pattern matching on 
strings is something that would make string-processing code 
much clearer and more concise. I don't mean that we have to 
use perforce the same "function" and "match" constructs that 
we use for "ordinary" pattern matching, yet some form of 
pattern matching over strings would be helpful.

> 
>>open Scanf
>>
>>... = function x -> begin
>>   try sscanf x "foo%[^]" foo with Scan_failure _ ->
>>   try sscanf x "bar%[^]" bar with Scan_failure _ ->
>>     raise Unrecognized
>>end
>>
> 
> you mean
> 
>  ... = function x -> begin
>     try sscanf x "foo%s" foo with Scan_failure _ ->
>     try sscanf x "bar%s" bar with Scan_failure _ ->
>       raise Unrecognized
>  end

I meant what I wrote. The %s conversion stops reading at the 
  first whitespace character. However, ocaml does not like 
the  "%[^]" which, in my opinion, is to be considered a 
mini-bug. "%[^]" should be interpreted as "the set of all 
characters except none", which is "the set of all 
characters", which can also be expressed, more verbosely, as 
"%[\000-\255]". By the same standards, "%[]" is rejected, 
when it should be interpreted as "the set containing no 
characters", or more verbosely "%[^\000-\255]"


> 
> 
>>An equivalent mapping could be done with the Str library or 
>>any other regexp library.
> 
> Those libs are optional.... (at present).
> 
> I agree, having some kind of fusion between ML pattern-matching and
> regexp-matching is an issue, there is research work on this.
> But this means lot of work...
> 
> --Luc

Do you know of any literature on the subject which I might 
give a look at?

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-10-02 16:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-02 14:12 [Caml-list] Pattern matching and strings Alessandro Baretta
2002-10-02 15:02 ` Luc Maranget
2002-10-02 16:21   ` Alessandro Baretta [this message]
2002-10-02 17:15     ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Luc Maranget
2002-10-02 18:30       ` Alessandro Baretta
2002-10-02 18:32         ` Benjamin C. Pierce
2002-10-04 13:01       ` Florian Douetteau
2002-10-04  9:07     ` Pierre Weis
2002-10-04  9:31       ` Alessandro Baretta
2002-10-04 10:03         ` Pierre Weis
2002-10-04 10:23           ` Alessandro Baretta
2002-10-04 12:11             ` Remi VANICAT
2002-10-04 12:40               ` [Caml-list] Ocaml 3.06 Win2K OCAML/C link problem Ward Wheeler
2002-10-04 13:12               ` [Caml-list] Pattern matching and strings (and a mini-bug inScanf) Frederic van der Plancke
2002-10-04 19:31               ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Alessandro Baretta
2002-10-07  7:17                 ` Pierre Weis
2002-10-02 20:59 ` [Caml-list] views for strings (was: Pattern matching and strings) Chris Hecker
2002-10-02 23:09   ` [Caml-list] " Alessandro Baretta
2002-10-03  8:31 ` [Caml-list] Pattern matching and strings Sven Luther
2002-10-04 12:00   ` Andreas Rossberg
2002-10-04 14:21     ` Kontra, Gergely
2002-10-04 15:14     ` Luc Maranget
2002-10-04 19:38       ` Alessandro Baretta
2002-10-05  6:34         ` [Caml-list] Camlp4 (Was: Pattern matching and strings) Daniel de Rauglaudre
2002-10-05 12:47           ` Sven LUTHER
2002-10-05 12:42             ` Daniel de Rauglaudre
2002-10-05 13:41               ` Michel Mauny
2002-10-05 13:47                 ` Daniel de Rauglaudre
2002-10-05 14:09                   ` Michel Mauny
2002-10-05 18:13                     ` Alessandro Baretta
2002-10-05 20:30                       ` [Caml-list] Future of Camlp4 Daniel de Rauglaudre
2002-10-04 19:13     ` [Caml-list] Pattern matching and strings Sven LUTHER

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=3D9B1CF4.5030706@baretta.com \
    --to=alex@baretta.com \
    --cc=caml-list@inria.fr \
    --cc=luc.maranget@inria.fr \
    /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).