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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4FC10BC0A for ; Wed, 14 Feb 2007 19:55:30 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1EItTZ1018078 for ; Wed, 14 Feb 2007 19:55:30 +0100 Received: from [84.59.102.197] (helo=gate.lan.gerd-stolpmann.de) by mrelayeu.kundenserver.de (node=mrelayeu4) with ESMTP (Nemesis), id 0ML21M-1HHPHg0kIG-0002Ho; Wed, 14 Feb 2007 19:55:28 +0100 Received: from flakew.lan.gerd-stolpmann.de (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id C69C6C085; Wed, 14 Feb 2007 19:55:15 +0100 (CET) Subject: Re: [Caml-list] Patterns that evaluate From: Gerd Stolpmann To: Edgar Friendly Cc: Jon Harrop , caml-list@yquem.inria.fr In-Reply-To: <45D352F2.3080003@gmail.com> References: <45D23608.4030104@mcmaster.ca> <200702132207.33793.jon@ffconsultancy.com> <45D352F2.3080003@gmail.com> Content-Type: text/plain Date: Wed, 14 Feb 2007 19:55:13 +0100 Message-Id: <1171479313.24335.33.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:a6865a839c0178d9aa0ce41878507ea2 X-Provags-ID2: V01U2FsdGVkX18Y8MwfFkhE07ulw9YccpfKSohKGyvfrxq/hp3mrtIYjhIndYBwlG4oC+RMjnvwdHqZLrZJ1qSIjrssAoQ22lYGESJHm6GNeWIC4TaSdNgWiZ+vTLk3VvMO X-Miltered: at concorde with ID 45D35B21.003 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gerd:01 stolpmann:01 ocaml:01 ocaml's:01 bug:01 afaik:01 ocaml's:01 syntax:01 compiler:01 syntax:01 semantics:01 o'caml:01 gerd:01 stolpmann:01 viktoriastr:01 Am Mittwoch, den 14.02.2007, 12:20 -0600 schrieb Edgar Friendly: > Jon Harrop wrote: > > On Tuesday 13 February 2007 22:04, Jacques Carette wrote: > >> I recently wrote some ocaml code which "worked", but not as I > >> intended... The test cases I tried worked, but I should have tested > >> harder. Apparently I was under the mistaken impression that OCaml's > >> pattern-matching was more "first class"! So I wrote (in part): > >> > >> let buildsimp cast e f1 f2 = fun e1 -> fun e2 -> match (e1,e2) with > >> > >> | ({st = Some e}, _) -> e2 > >> > >> and I expected it to work. Only a code review by a colleague 'found' > >> this bug in my code. > >> > >> Question: would it be a difficult extension? This seemed so "natural", > >> I just "used" the feature before it was quite there yet ;-). > > > > F# just introduced active patterns, which does what you want AFAIK. Of course, > > you must disambiguate that from the OCaml's current interpretation of the > > above (binding "e"). > > > The two options I see are: > 1) noting a re-binding, and automatically testing against the value of > that previous binding > 2) extra syntax (maybe || instead of | before active match constructs) > > In the first case, there's backwards compatibility issues. Wouldn't it > be useful to have the compiler warn on such uses, to make people aware > of rebindings performed in their code? You are a bit quick. Before discussing syntax it is more important to define the semantics of such patterns. I mean we have already three predefined kinds of equality in O'Caml: - ( == ) - ( = ) - (fun x y -> compare x y = 0) I admit I do not prefer any one of them. So which equality should be used to test whether the variable is equal to the matched part of the value? I guess this simple question is one of the reasons why such a feature is not in the language up to now. Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------