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=1.4 required=5.0 tests=SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id BDA98BC69 for ; Tue, 25 Dec 2007 18:36:30 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CABjOcEfRVZK2kmdsb2JhbACDIoxtAgEBBwQEKZQcg2Q X-IronPort-AV: E=Sophos;i="4.24,206,1196636400"; d="scan'208";a="20681130" Received: from wa-out-1112.google.com ([209.85.146.182]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Dec 2007 18:36:30 +0100 Received: by wa-out-1112.google.com with SMTP id k17so3677643waf.3 for ; Tue, 25 Dec 2007 09:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=eKg5PGb9mgpXMH669lAPz3XoOOmcyD7pvO+/g4tmpks=; b=JJ8Vg6m5Ijj9RL4ewh3qi6GyJVXyHvSYXIVcXUiBL0kQV455hog0CDe2+bSvOwQlK/seoNfYD4gLRJ4n1hm4Rb/IksqBiWSdll0XjzaXa/jAmJTzXXdik+mnacdloJ7x+fvvEE8l2HW15o/NX09LL7fYQWSOoF5KTpdQLZdcMHc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=hK52bui0eIc+rpoJsWjh/api3dJdTbYuzjG93jXOVxpMziEKibSK6kVQpCgvlttjlTnUD6hMfTty+xFXnV5AZ3D5B0BRxmc9Uc3ARhsGfqCSz0/YlouIDUC5w45/MEPvkFloCcVhPqfqahd9T8l3G6MoXmf3TWhvWzTm9kLOZJ0= Received: by 10.142.84.3 with SMTP id h3mr1686785wfb.113.1198604187878; Tue, 25 Dec 2007 09:36:27 -0800 (PST) Received: by 10.142.173.15 with HTTP; Tue, 25 Dec 2007 09:36:27 -0800 (PST) Message-ID: <527cf6bc0712250936k7b7c713eg7ec4a34da4fd2f26@mail.gmail.com> Date: Tue, 25 Dec 2007 18:36:27 +0100 From: "blue storm" To: caml-list@yquem.inria.fr Subject: [camlp4 extension] pa_refutable : request for comments MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Spam: no; 0.00; camlp:01 camlp:01 syntax:01 foo:01 runtime:01 failwith:01 expr:01 expr:01 subtleties:01 storm:98 rec:01 rec:01 parsing:01 patt:01 patt:01 Hi, I just created my first "serious" camlp4 (3.10) extension. I'm looking for comments, and have some questions too. The extension (to the classical syntax) enables an explicit use of non-irrefutable pattern matching in "let" declarations : let refutable hd::tl = ... let refutable [a; b; c] = List.map foo ['a'; 'b'; 'c'] let rec refutable func (Some thing) = ... The code is available here : http://bluestorm.info/tmp/pa_refutable.ml.html (side question : are 80 lines of code short enough to be included in my message ? what is the mailing-list recommended behaviour here ?) The actual error-reporting is rather naive : the extension generate a string containing the location of the refutable pattern in the original source, wich is raised at runtime using "failwith".. Is there a more elegant way to do that ? There are 6 repetitive lines of code in my refutable_mono function : let binds_patt binds _loc = let patt_of_id (id, _loc) = <:patt< $lid:id$ >> in Ast.PaTup _loc (Ast.paCom_of_list (List.map patt_of_id binds)) in let binds_expr binds _loc = let expr_of_id (id, _loc) = <:expr< $lid:id$ >> in Ast.ExTup _loc (Ast.exCom_of_list (List.map expr_of_id binds)) in Is there an better way to do this ? Lastly, i had to duplicate work in the grammar-modification part, because i didn't manage to use the "opt_rec" rule. I'm not aware of the subtleties of camlp4 parsing; is there another way ?