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 65782BB84 for ; Tue, 9 May 2006 15:49:29 +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 k49DnS77032292 for ; Tue, 9 May 2006 15:49:29 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA30538 for ; Tue, 9 May 2006 15:49:28 +0200 (MET DST) Received: from [128.93.11.101] (buzet.inria.fr [128.93.11.101]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k49DnS7K032285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 May 2006 15:49:28 +0200 Message-ID: <44609D8F.4040100@inria.fr> Date: Tue, 09 May 2006 15:47:59 +0200 From: Alain Frisch User-Agent: Thunderbird 1.5.0.2 (X11/20060501) MIME-Version: 1.0 To: Christophe Raffalli Cc: caml-list Subject: Re: [Caml-list] is this a bug ? References: <44609473.6030004@univ-savoie.fr> In-Reply-To: <44609473.6030004@univ-savoie.fr> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44609DE9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44609DE8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; frisch:01 frisch:01 bug:01 christophe:01 raffalli:01 backtracking:01 wrote:01 caml-list:01 int:01 int:01 newline:02 caml:02 match:02 match:02 binding: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 Christophe Raffalli wrote: > > hello, > > -------------------------------- > 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" ? Well, both happens, right? I don't see any problem. The pattern [_;a] is useless because [a;_] matches the same values and the first match (left-to-right) policy is specificed (http://caml.inria.fr/pub/docs/manual-ocaml/manual014.html). The guard is checked after the binding, and there is no backtracking. This explains why the function returns 3 when b=1 l=[2;1]. -- Alain