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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 58B32BBC1 for ; Fri, 25 Apr 2008 16:00:21 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAFOAEUjAXQIm/2dsb2JhbACsVg X-IronPort-AV: E=Sophos;i="4.25,707,1199660400"; d="scan'208";a="10056144" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 25 Apr 2008 16:00:21 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m3PE00uN008534 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 25 Apr 2008 16:00:21 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqsEAA2BEUhCbwQZjmdsb2JhbACRWgEBAQEJAwoHDwWaRg X-IronPort-AV: E=Sophos;i="4.25,707,1199660400"; d="scan'208";a="25492208" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Apr 2008 15:59:59 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 4C593102AA5; Fri, 25 Apr 2008 09:59:58 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Fri, 25 Apr 2008 09:59:58 -0400 X-Sasl-enc: VenBe5siF0U+tyBlqesnx9OrbgKm8WWWLk7x7lC1Qy/9 1209131997 Received: from [192.168.1.10] (ALyon-157-1-7-80.w90-28.abo.wanadoo.fr [90.28.182.80]) by mail.messagingengine.com (Postfix) with ESMTPSA id 827E11B1F0; Fri, 25 Apr 2008 09:59:57 -0400 (EDT) Date: Fri, 25 Apr 2008 15:58:17 +0200 (CEST) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Two camlp4 questions In-Reply-To: <20080425131812.GB4100@annexia.org> Message-ID: References: <20080425131812.GB4100@annexia.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 4811E3E0.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 camlp:01 camlp:01 expr:01 compile-time:01 expr:01 syntax:01 hacked:01 beginner's:01 ocaml:01 bug:01 beginners:01 wrote:01 matched:01 assert:01 On Fri, 25 Apr 2008, Richard Jones wrote: > (1) How do I match on the pattern which is literally '_' in the > original code? > > match mypatt with > | <:patt< _ >> -> ... > > seems like it matches any pattern. Strange. > (2) Is there a function hiding anywhere which tests whether a pattern > is exhaustive? It's something that can't be done with camlp4. If in some module M, some type t is defined by "type t = A | B | C" then knowing that "M.A -> 1 | M.B -> 2" is incomplete requires access to more information than camlp4 has. > Here's the problem I have: I want to generate code > like this: > > <:expr< match $someexpr$ with $mypatt$ -> $code$ | _ -> () >> > > However this gives a compile-time warning if mypatt is already > exhaustive because the second case could never be matched. If mypatt > is already exhaustive then I'd want to generate this code instead to > avoid the warning: > > <:expr< match $someexpr$ with $mypatt$ -> $code$ >> One possible hack is to add "when true" guards everywhere and one final "| _ -> assert false" case. This disables completeness checking and turns off warnings, at your own risk. Note: "assert false" is not ideal, since you want to raise Match_failure with the proper location. <:expr< match () with [] >> should do it (assuming quotations in the revised syntax) > I hacked around it a little with this function: > > let pattern_is_exhaustive = function > | <:patt< $lid:_$ >> -> true > | _ -> false > > but I guess you can see that this function is not a complete solution. > > Rich. > > -- > Richard Jones > Red Hat > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- http://wink.com/profile/mjambon http://mjambon.com