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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 0C261BB9C for ; Wed, 23 Nov 2005 21:56:49 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jANKumc6016612 for ; Wed, 23 Nov 2005 21:56:48 +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 VAA11153 for ; Wed, 23 Nov 2005 21:56:48 +0100 (MET) Received: from smtp.cegetel.net (217-19-192-73.dti.cegetel.net [217.19.192.73]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANKulpS002892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 23 Nov 2005 21:56:47 +0100 Received: from [192.168.144.2] (80-125-86-59.adslgp.cegetel.net [80.125.86.59]) by smtp.cegetel.net (Postfix) with ESMTP id 5A94D6A042F; Wed, 23 Nov 2005 21:56:42 +0100 (CET) Message-ID: <4384D785.5010106@univ-savoie.fr> Date: Wed, 23 Nov 2005 21:56:37 +0100 From: Christophe Raffalli User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: fr, en MIME-Version: 1.0 To: Luc Maranget Cc: sejourne_kevin , caml-list Subject: Re: [Caml-list] Request for complete pattern matching References: <43839F1A.2080909@univ-savoie.fr> <43842069.3070700@yahoo.fr> <43848103.9060504@univ-savoie.fr> <20051123183134.GB6446@yquem.inria.fr> In-Reply-To: <20051123183134.GB6446@yquem.inria.fr> X-Enigmail-Version: 0.93.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig11247FA59956437F8A41C016" X-Miltered: at nez-perce with ID 4384D790.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4384D78F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 caml-list:01 replacing:01 en':01 camlp:01 compilation:01 doable:01 matchings:01 compiler:01 camlp:01 semantics:01 X-Attachments: type="application/pgp-signature" name="signature.asc" name="signature.asc" 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 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig11247FA59956437F8A41C016 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > > 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! > I agree that your translation works (I should try). I am just wondering about the cost (compared to a reasonable implementation inside the compiler) ? That would probably be not so dramatic ... except I should not transform pattern matching that do not use the new extension ... the camlp4 code will probably tripple what I have. Moreover, I think I may use camlp4 for bindlib-3.0, because this really is an extension of the language and not a library ... however I do not think camlp4 extensions are a good thing in general, because it breaks readability of code. So for my extension of pattern matching with function application, I think, I prefer to wait an adoption of a similar feature rather than doing it myself. bindlib-3.0 will be ok without this extention of the pattern matching. One of the reason for my post, is that I think pattern matching should be complete (one of the reason, is because then you can interpret the semantics of the language by the interaction of a constructor and a destructor ... this has something to do with a lot of reasearch work in computational interpretation of classical logic ... and trying to move the language in this direction looks fun ..., for instance have a look at Herbelin's work) > > -- Luc --------------enig11247FA59956437F8A41C016 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iQIVAwUBQ4TXiJEBCSatcik9AQLowxAAmIUoPrLovyAO93b425QDA1S929Udzqgm orA7UvSsXHbAnJ6VwAkqAQrZ1NSUPEB26Zf8I6XszAKs9i9ljqzQ0Ow4BXtUGEkc XZ/1NOGp+d7MnJEGgzvmyTngSal6tvFrMuuZDZe+XD5wuNrzl/P9n8HiuLNLwJmm 348XcChH2gDQzuJOKS2jyCT4zbjg4Ql/QGFLC1F4ZcCQ6kAfyVVUXpxypGs9jdID JYnjtMQD3HV7IE7sGcjLufN1Ag2hS8JOtmXTKng15ghcXSaZhrSfNkELK8y6a9/p D+btZIedPbTJsrOF7HhUKKyVb8KFkxPZf+6h7MUaGCBzxEgw/T6V6jjOxhuQRyz3 gHCe/TmEXe/KoXfT6x7aDyXDd/kzEC6Vw6SY9odY7HG7YeobkkoYRZCH67KxB0rc jgMjt8m2FgTszgVWG3VqX0GdIbyioHYYjnRRqSAWoSccWQvUsyyTKPmtA4ej6Yel JZl0B4UXvu+YyychSGyMCPCTDsYfxSBv5xb7vXEPQUxFAv/nzsQqogY8GbbZiQ4u eeacvlaCphKw/0Guj1DRvoeyBjLYg3fl14sR4mM/Ke9kzBt98SeeeMHfFkXJxity cVYUlkYcIBRO0HmAYjD5lTMkjXGcWgMoVKOyTdaK5psgSKgYNIXcOVDlmXayvoUx 6pTXgXoRWj0= =pyy+ -----END PGP SIGNATURE----- --------------enig11247FA59956437F8A41C016--