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 C4E6CBB84 for ; Tue, 9 May 2006 15:33:11 +0200 (CEST) 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 k49DXB8N029888 for ; Tue, 9 May 2006 15:33:11 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA30007 for ; Tue, 9 May 2006 15:33:10 +0200 (MET DST) Received: from ron.emn.fr (sicnat2.emn.fr [193.54.76.193]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k49DXAjH011329 for ; Tue, 9 May 2006 15:33:10 +0200 Received: from spip.dsic.emn.fr (root@spip.dsic.emn.fr [193.104.32.156]) by ron.emn.fr (8.9.3/jtpda-5.3.1) with ESMTP id PAA29172 ; Tue, 9 May 2006 15:32:07 +0200 (CEST) Received: from ifs.emn.fr (ifs.emn.fr [193.54.76.100]) by spip.dsic.emn.fr (8.12.1/8.12.1) with ESMTP id k49DX6bT011124; Tue, 9 May 2006 15:33:06 +0200 Received: from localhost.localdomain (pad@dhcp109.rech18.emn.fr [192.168.18.109]) by ifs.emn.fr (8.9.3/jtpda-5.1) with ESMTP id PAA26661 ; Tue, 9 May 2006 15:31:45 +0200 (MEST) To: Samuel Mimram Cc: Christophe Raffalli , caml-list Subject: Re: [Caml-list] is this a bug ? References: <44609473.6030004@univ-savoie.fr> <446096F0.6000405@ens-lyon.org> From: Yoann Padioleau Date: Tue, 09 May 2006 15:30:41 +0200 In-Reply-To: <446096F0.6000405@ens-lyon.org> (Samuel Mimram's message of "Tue, 09 May 2006 15:19:44 +0200") Message-ID: <87u07zwcji.fsf@wanadoo.fr> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-j-chkmail-Score: MSGID : 44609A16.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at concorde with ID 44609A17.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44609A16.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bug:01 ens-lyon:01 christophe:01 raffalli:01 bug:01 'when':01 cheers:01 beginner's:01 ocaml:01 beginners:01 wrote:01 writes:01 caml-list:01 caml-list:01 parsed: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.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Samuel Mimram writes: > Hi, > > Christophe Raffalli wrote: >> -------------------------------- >> let f b l = match l with >> [] | [_] -> 1 >> | [a;_] | [_;a] when a = b-> 2 >> | _ -> 3 >> >> let _ = >> print_int (f 1 [1;2]); >> print_int (f 1 [2;1]); >> print_newline () >> -------------------------------- >> >> Do you think this code should have a useless pattern warning and print >> "23" instead of "22" ? >> >> If someone tell me this is a bug then I fill a bug report ... > > I guess that the priorities says that you should "read" the third line as > > | [a;_] | ( [_;a] when a = b ) -> 2 I am not sure because because | ([a;_] | [_;a]) when a = b -> 2 issues the same warning. I think | [a;_] | [_;a] when a = b-> 2 is parsed as | ( [a;_] | [_;a]) when a = b -> 2 but that the semantic is first to look at the pattern, and if one is found, then look at the condition, which is too late. 'when' does not "distribute" over Or-patterns :( let f b l = match l with [] | [_] -> 1 | [a;_] when a = b-> 2 | [_;a] when a = b-> 2 | _ -> 3 works. > > This would justify the warning and explain the behaviour... > > Cheers, > > Samuel. > > _______________________________________________ > 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 > > -- pad