From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 466C5BC6B for ; Wed, 27 Jun 2007 20:31:37 +0200 (CEST) Received: from smtp.janestcapital.com (www.janestcapital.com [66.155.124.107]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RIVZGp028428 for ; Wed, 27 Jun 2007 20:31:36 +0200 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id AD180158; Wed, 27 Jun 2007 14:31:52 -0400 Message-ID: <4682AD06.9080008@janestcapital.com> Date: Wed, 27 Jun 2007 14:31:34 -0400 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments References: <200706271314.35134.jon@ffconsultancy.com> <46828488.3000006@SmokejumperIT.com> <200706271548.l5RFmiS04436@virtutech.se> <200706271906.07626.jon@ffconsultancy.com> In-Reply-To: <200706271906.07626.jon@ffconsultancy.com> Content-Type: multipart/alternative; boundary="------------000102070107000007090306" X-j-chkmail-Score: MSGID : 4682AD07.004 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 4682AD07.004 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; mattias:01 ocaml:01 compiler:01 arrays:01 variants:01 val:01 val:01 foo:01 baz:01 foo:01 baz:01 ocamllex:01 mattias:01 ocaml:01 compiler:01 This is a multi-part message in MIME format. --------------000102070107000007090306 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Jon Harrop wrote: >On Wednesday 27 June 2007 16:48:44 Mattias Engdegård wrote: > > >>The cost is a slightly clumsier use of symbols as strings (Symbol.str), >>but my feeling is that the extra safety is worth it. >> >> > >That is exactly what I did. Also, you cannot pattern match over the Sym.t but >I believe the OCaml compiler doesn't optimize pattern matches over strings >anyway. > >Incidentally, can we add this to the list of wanted optimizations: O(log n) >matching of strings, arrays and polymorphic variants. > > > Actually, what I'd like is a more powerful regular expression engine- one where I can give multiple different patterns with constant values, and create a single regular expression that if the first pattern is matched, the first constant value is matched, etc. Something with a signature like: type 'a regex_t val compile : (string * 'a) -> default:'a -> 'a regex_t val re_match : 'a regex_t -> string -> 'a Which would allow me to do stuff like: let re = compile [ ("foo", 1); ("bar", 2); ("baz", 3) ] ~default:(-1);; let f str = match re_match re str with | 1 -> (* it's a foo *) | 2 -> (* it's a bar *) | 3 -> (* it's a baz *) | -1 -> (* it didn't match *) ;; In other words, something like ocamllex, except dynamic. Brian --------------000102070107000007090306 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Jon Harrop wrote:
On Wednesday 27 June 2007 16:48:44 Mattias Engdegård wrote:
  
The cost is a slightly clumsier use of symbols as strings (Symbol.str),
but my feeling is that the extra safety is worth it.
    

That is exactly what I did. Also, you cannot pattern match over the Sym.t but 
I believe the OCaml compiler doesn't optimize pattern matches over strings 
anyway.

Incidentally, can we add this to the list of wanted optimizations: O(log n) 
matching of strings, arrays and polymorphic variants.

  
Actually, what I'd like is a more powerful regular expression engine- one where I can give multiple different patterns with constant values, and create a single regular expression that if the first pattern is matched, the first constant value is matched, etc.  Something with a signature like:

type 'a regex_t
val compile : (string * 'a) -> default:'a -> 'a regex_t
val re_match : 'a regex_t -> string -> 'a

Which would allow me to do stuff like:

let re = compile [ ("foo", 1); ("bar", 2); ("baz", 3) ] ~default:(-1);;

let f str =
    match re_match re str with
    | 1 -> (* it's a foo *)
    | 2 -> (* it's a bar *)
    | 3 -> (* it's a baz *)
    | -1 -> (* it didn't match *)
;;

In other words, something like ocamllex, except dynamic.

Brian

--------------000102070107000007090306--