From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA26456; Mon, 1 Dec 2003 16:43:11 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 QAA28003 for ; Mon, 1 Dec 2003 16:43:10 +0100 (MET) Received: from mailhost.tni.fr (firewall.tni.fr [195.25.255.61]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hB1FhAr21469 for ; Mon, 1 Dec 2003 16:43:10 +0100 (MET) Received: from groscool.tni.fr ([127.0.0.1]) by mailhost.tni.fr (Netscape Messaging Server 3.62) with SMTP id 464 for ; Mon, 1 Dec 2003 16:42:52 +0100 Received: from 192.168.7.60 by groscool.tni.fr (InterScan E-Mail VirusWall NT); Mon, 01 Dec 2003 16:42:52 +0100 Message-ID: <3FCB610E.932B363B@tni.fr> Date: Mon, 01 Dec 2003 16:41:02 +0100 From: "sebastien FURIC" X-Mailer: Mozilla 4.78 [fr] (Windows NT 5.0; U) X-Accept-Language: fr MIME-Version: 1.0 To: OCaml Mailing list Subject: [Caml-list] Question Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; furic:01 furic:01 tni-valiosys:01 toto:01 toto:01 val:01 ocaml's:01 val:01 int:01 int:01 behaviour:01 match:02 match:02 titi:02 titi:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, What do you think of the following code? # type toto = Toto of int | Titi of string;; type toto = Toto of int | Titi of string # let test t t' = match t, t' with | ((Toto _ | Titi _), Toto x | Toto x, (Toto _ | Titi _)) when x = 0 -> "OK" | _ -> "KO";; Characters 73-79: Warning: this pattern is unused. | ((Toto _ | Titi _), Toto x | Toto x, (Toto _ | Titi _)) when x = 0 -> "OK" ^^^^^^ val test : toto -> toto -> string = # test (Toto 0) (Toto 1);; - : string = "KO" I was expecting "when" to be right distributive over "|". I find OCaml's behaviour not very intuitive in such a situation. The correct code is: # let test t t' = match t, t' with | (Toto _ | Titi _), Toto x when x = 0 -> "OK" | Toto x, (Toto _ | Titi _) when x = 0 -> "OK" | _ -> "KO";; val test : toto -> toto -> string = # test (Toto 0) (Toto 1);; - : string = "OK" Is there a good reason for this? Cheers, Sébastien. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners