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.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 68B48BBCA for ; Wed, 27 Feb 2008 23:09:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEtuxUfAXQInh2dsb2JhbACQaAEBAQgKKZUqh34 X-IronPort-AV: E=Sophos;i="4.25,415,1199660400"; d="scan'208";a="8684493" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Feb 2008 23:09:07 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1RM96mb030545 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 27 Feb 2008 23:09:07 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANJtxUdA6aa2emdsb2JhbACQaAEBCQQECgkRBZUkh34 X-IronPort-AV: E=Sophos;i="4.25,415,1199660400"; d="scan'208";a="9678141" Received: from py-out-1112.google.com ([64.233.166.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 27 Feb 2008 23:09:05 +0100 Received: by py-out-1112.google.com with SMTP id u52so4730248pyb.10 for ; Wed, 27 Feb 2008 14:09:05 -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:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=fzvVObkvcopA+kCasfuOIqu2W6ZWzBxWcit1LBiactQ=; b=ktELtLq5hBqNmRuRqybPC4Pv0dl3kTFNzdzowbxCcY72mk5YSasg+9yTgvGgNBIzl3OQnp7iMp/3xtdQw/7/hvp+/ZowxhrBDxbBwrs4SORYl3ZObqiXUaJ5SCC53BTzhU8IrwrR7Iv6k29Gc03xbRSIUK0kMSdtNmB9xPGKfjs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=RP6DzOdiJmVFrHkg4OF95f2GBbLd3Ip0GKrqd1fpX6G4WEa2ENQG2jdYtEeI9oQD6veN6HBKXMaH/H7e+vHByhNBVkR07GIibmYWvczGYSYuTgZkNkloiljjhmeJUZxTZBP08zyCvYe4WMjnEr21BsFWinP+rdKdGEipsTrWA3Q= Received: by 10.35.62.19 with SMTP id p19mr8308412pyk.4.1204150143465; Wed, 27 Feb 2008 14:09:03 -0800 (PST) Received: from ?192.168.0.16? ( [69.154.33.47]) by mx.google.com with ESMTPS id y64sm8683261pyg.22.2008.02.27.14.09.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 27 Feb 2008 14:09:02 -0800 (PST) Message-ID: <47C5DF7C.4010107@gmail.com> Date: Wed, 27 Feb 2008 16:09:00 -0600 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: David Teller Cc: OCaml Subject: Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know References: <1204147958.7005.17.camel@Blefuscu> In-Reply-To: <1204147958.7005.17.camel@Blefuscu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 47C5DF82.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 catch-all:01 semantics:01 rewriting:01 compiler:01 compiler:01 'when':01 edgar:98 wrote:01 caml-list:01 match:02 match:02 seems:03 clause:03 clause:03 David Teller wrote: > Dear list, > > I'm currently working on a little Camlp4 extension which has to often > generate pattern-matching clauses depending on user code -- and deal > with match failures accordingly. > > Now, I guess > > 1. I can wrap the user's pattern-matching inside a try...with, catch any > Match_failure and deal with it. This seems hackish. > 2. I can add a catch-all clause " _ -> deal_with_error ". While the > semantics of this rewriting are exactly what I need, the compiler tends > to print "Warning U: this match case is unused" whenever the user has > already taken care of all cases. It may seem that you've taken care of all cases, but keep in mind that the compiler looks at a match case containing a 'when' clause and assumes that clause can cause the match to fail, independent of all other terms. i.e. if you write: match 123 with | x when x mod 2 = 1 -> "Odd" | x when x mod 2 = 0 -> "Even" The compiler can't see that you've covered all cases. Even the following generates a warning: match 123 with x when true -> "TRUE" | x when false -> "FALSE" The way I write this style of matching goes like this: match 123 with | x when x mod 2 = 1 -> "Odd" | x (* x mod 2 = 0 *) -> "Even" Can you structure your matches this way? E.