From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 EFC95BB9C for ; Wed, 23 Nov 2005 19:31:35 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANIVZYm021124 for ; Wed, 23 Nov 2005 19:31:35 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA09538 for ; Wed, 23 Nov 2005 19:31:35 +0100 (MET) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANIVYiY021117; Wed, 23 Nov 2005 19:31:34 +0100 Received: by yquem.inria.fr (Postfix, from userid 18041) id 900CFBB9C; Wed, 23 Nov 2005 19:31:34 +0100 (CET) Date: Wed, 23 Nov 2005 19:31:34 +0100 To: Christophe Raffalli Cc: sejourne_kevin , caml-list Subject: Re: [Caml-list] Request for complete pattern matching Message-ID: <20051123183134.GB6446@yquem.inria.fr> References: <43839F1A.2080909@univ-savoie.fr> <43842069.3070700@yahoo.fr> <43848103.9060504@univ-savoie.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43848103.9060504@univ-savoie.fr> User-Agent: Mutt/1.5.9i From: luc.maranget@inria.fr (Luc Maranget) X-Miltered: at concorde with ID 4384B587.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4384B586.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 maranget:01 maranget:01 replacing:01 en':01 camlp:01 compilation:01 doable:01 matchings:01 luc:01 luc:01 typing:01 syntactic:01 syntactic:01 compile:01 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 > > No this is not a problem of test. I want to be able to write > > match e with > (0 <= 0, g) -> g > | (f, 0 <= 0) -> f > | (f, g) -> fun x -> f x + g x > Well, I understand better and (as you may have guessed yourself!) I do not incline to adopt the idea. However provided you have some 'break' construct to transfert control to next matching, you can perhaps compile your construct by syntactic transformation. My idea is to transform your patterns into normal ones, replacing p <= e1 e2 ... en by fresh variables (say v) and then to match 'v e1 ... en' against p. Here you have : match e with | (v1, g) -> (match v1 0 with 0 -> g |_ -> break) | (f, v2) -> (match v2 0 with 0 -> f |_ -> break) | f, g -> fun x -> f x + g x At a little additional cost in complexity, you can replace 'break' (which does not exists) by exceptions as follows let x = e in try (match x with | (v1, g) -> (match v1 0 with 0 -> g |_ -> raise Exit) | _ -> raise Exit) with Exit -> try (match x with | (f, v2) -> (match v2 0 with 0 -> f |_ -> raise Exit) | _ -> raise Exit) with Exit -> (match x with f, g -> fun x -> f x + g x) I am not familiar enough with Camlp4, but I have the feeling that some purely syntactic compilation of your construct is doable. Since, only from the presence of <=, can you introduce the extra matchings and try .. with Exit) I am not saying it is easy, just that it looks feasible. Typing and warnings are yet another issue! -- Luc