From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 1406CBCA2 for ; Wed, 17 Aug 2005 14:19:29 +0200 (CEST) Received: from [128.93.11.101] (buzet.inria.fr [128.93.11.101]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7HCJSEE013730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 17 Aug 2005 14:19:28 +0200 Message-ID: <43032B50.40902@inria.fr> Date: Wed, 17 Aug 2005 14:19:28 +0200 From: Alain Frisch User-Agent: Debian Thunderbird 1.0.2 (X11/20050602) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Snd question References: <161F0D30A699A84A8B7435B62BCE33B30360E19F@APS-MSG-01.southpacific.corp.microsoft.com> <43011A10.4090108@havenrock.com> <1124198264.13635.25.camel@localhost.localdomain> <200508161734.38909.jon@ffconsultancy.com> <20050816181604.GA21719@furbychan.cocan.org> In-Reply-To: <20050816181604.GA21719@furbychan.cocan.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43032B50.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; frisch:01 frisch:01 caml-list:01 ocaml:01 ocamlduce:01 ocaml:01 ocamlduce:01 'o':01 'o':01 val:01 ...:98 wrote:01 wrote:01 patterns:02 prefixes:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Richard Jones wrote: > On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote: > >>Currently, you cannot match [|1; ...|] in OCaml. > > > Yes! Or, "prefix" ^ str. This seems like a good place to insert a shameless plug. Thank you. In OCamlDuce (the extension of OCaml with XML types and patterns), you can indeed match on string prefixes: # type t = {{ "OCaml" | "OCamlDuce" | "Other" }};; type t = {{t}} # fun (x : t) -> match x with {{ [ 'O' x::PCDATA ] }} -> x;; - : {{t}} -> {{[ 'ther' | 'Caml' | 'CamlDuce' ]}} = You can actually match on more complex regular expressions. E.g., to extract all the uppercase ASCII characters: # fun (x : t) -> match x with {{ [ (x::'A'--'Z' | _)* ] }} -> x;; - : {{t}} -> {{[ 'OC' | 'OCD' | 'O' ]}} = or to split a string: # let f (x : {{String}}) : {{String}} * {{String}} = match x with {{ [ x::PCDATA '.' y::PCDATA ] }} -> (x,y) | {{_}} -> raise Not_found;; val f : {{String}} -> {{String}} * {{String}} = -- Alain