From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA13076; Wed, 2 Oct 2002 18:11:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA07502 for ; Wed, 2 Oct 2002 18:11:15 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a241.tin.it [62.211.4.241]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g92GBED00159; Wed, 2 Oct 2002 18:11:14 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id AB61C2739E; Wed, 2 Oct 2002 18:21:08 +0200 (CEST) Message-ID: <3D9B1CF4.5030706@baretta.com> Date: Wed, 02 Oct 2002 18:21:08 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Luc Maranget , Ocaml Subject: Re: [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) References: <200210021502.RAA0000000423@beaune.inria.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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