From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E5E1CBC75 for ; Mon, 28 Feb 2005 11:35:19 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1SAZJGt007142 for ; Mon, 28 Feb 2005 11:35:19 +0100 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 LAA25777 for ; Mon, 28 Feb 2005 11:35:19 +0100 (MET) Received: from alex.barettalocal.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1SAZICg007133 for ; Mon, 28 Feb 2005 11:35:18 +0100 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by alex.barettalocal.com (Postfix) with ESMTP id EA8502BAC11; Mon, 28 Feb 2005 11:35:17 +0100 (CET) Message-ID: <4222F3E5.4010704@barettadeit.com> Date: Mon, 28 Feb 2005 11:35:17 +0100 From: Alex Baretta User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20050105 Debian/1.7.5-1 X-Accept-Language: it, en-us, en MIME-Version: 1.0 To: Keith Wansbrough , Ocaml Subject: Re: [Caml-list] Fragile pattern matching?! References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4222F3E7.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4222F3E6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 caml-list:01 wrote:01 baretta:01 compiler:01 checker:01 checker:01 silently:01 bug:01 compiler:01 exception:01 exception:01 writes:01 constructor:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.9 required=5.0 tests=FORGED_RCVD_HELO,PLING_QUERY autolearn=disabled version=3.0.2 X-Spam-Level: Keith Wansbrough wrote: > Alex Baretta writes: > > >>let to_int value = match value with >> | Int x -> x >> | _ -> raise Some_exception >> >>The compiler signals a warning for a fragile pattern matching at the "_" >>character. >> >>Why in the world should this code signal such a warning? > > > The reason is to do with code maintenance. When in future you add > another constructor to the value type, the type checker will tell you > the locations of all matches that have now become incomplete, so that > you can fix them. But the match in "to_int" above will never become > incomplete. If the type checker passed this silently, then a bug > could easily be introduced. Hence the warning. I understand the need for this kind of warning, but it seems to me that I have used the "match x with Something -> do_something x | _ -> raise_an_exception" for years. Suddenly, I see the compiler signal warnings where I would not expect to seen them. What is the exact definition of fragile pattern matching? Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project