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 C7C32BB84 for ; Tue, 9 May 2006 15:33:24 +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 k49DXOir029936 for ; Tue, 9 May 2006 15:33:24 +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 PAA30280 for ; Tue, 9 May 2006 15:33:23 +0200 (MET DST) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k49DXNPR011445; Tue, 9 May 2006 15:33:23 +0200 Received: by yquem.inria.fr (Postfix, from userid 18041) id 86AA6BB84; Tue, 9 May 2006 15:33:23 +0200 (CEST) Date: Tue, 9 May 2006 15:33:23 +0200 To: Christophe Raffalli Cc: caml-list Subject: Re: [Caml-list] is this a bug ? Message-ID: <20060509133323.GA32191@yquem.inria.fr> References: <44609473.6030004@univ-savoie.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44609473.6030004@univ-savoie.fr> User-Agent: Mutt/1.5.9i From: luc.maranget@inria.fr (Luc Maranget) X-Miltered: at concorde with ID 44609A24.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44609A23.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bug:01 maranget:01 maranget:01 bug:01 semantics:01 semantics:01 or-pat:01 oups:01 --luc:01 luc:01 luc:01 caml-list:01 int:01 int:01 newline:02 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 > > hello, > > -------------------------------- > let f b l = match l with > [] | [_] -> 1 > | [a;_] | [_;a] when a = b-> 2 ^^^^ > | _ -> 3 Warning U: this pattern is unused. > > let _ = > print_int (f 1 [1;2]); > print_int (f 1 [2;1]); > print_newline () > -------------------------------- 23 > > 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 ... > You may object the semantics, but it is consitent w.r.t. both documentation (deterministic left-to-right matching of or-patterns, semantics of when as match first, then test) and supplied warning (which you omit). So I am tempted to say not a bug. However, there is indeed a difficulty, if we expand or-pat as: let f b l = match l with | [] -> 1 | [_] -> 1 | [a;_] when a = b -> 2 | [_;a] when a = b -> 2 | _ -> 3 Then, we have the other behavior (no warning, 22). Oups, another oddity of 'when...' --Luc