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 C58D4BC75 for ; Mon, 28 Feb 2005 11:40:00 +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 j1SAe0nZ007853 for ; Mon, 28 Feb 2005 11:40:00 +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 LAA25873 for ; Mon, 28 Feb 2005 11:40:00 +0100 (MET) 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 j1SAdxdv007835; Mon, 28 Feb 2005 11:39:59 +0100 Received: by yquem.inria.fr (Postfix, from userid 18041) id 12AF1BC75; Mon, 28 Feb 2005 11:39:59 +0100 (CET) Date: Mon, 28 Feb 2005 11:39:59 +0100 To: Alex Baretta Cc: Ocaml , Luc Maranget Subject: Re: [Caml-list] Fragile pattern matching?! Message-ID: <20050228103959.GA31015@yquem.inria.fr> References: <4222EF9E.1030106@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4222EF9E.1030106@barettadeit.com> User-Agent: Mutt/1.3.28i From: luc.maranget@inria.fr (Luc Maranget) X-Miltered: at nez-perce with ID 4222F500.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4222F4FF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 luc:01 maranget:01 luc:01 maranget:01 bool:01 bool:01 compiler:01 ocamlc:01 constructors:01 defaults:01 ocaml:01 ocamlc:01 compiler:01 -help: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=PLING_QUERY autolearn=disabled version=3.0.2 X-Spam-Level: > We have an incomprehensibile warning when compiling code that looks like > the following: > > type value = > | Int of int > | Float of float > | Int32 of int32 > | Int64 of int64 > | Bool of bool > | String of string > > 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? > > Alex > > > -- Hello, The warning (which you do not supply) attempt to be informative. # ocamlc -w A alex.ml File "alex.ml", line 13, characters 4-5: Warning E: this pattern is fragile. It would hide the addition of new constructors to the data types it matches. This warning has been introduced in response to user demand. The idea is to enforce some coding rule that promotes robustness. However the coding rule is so strict that it was decided that standard users can ignore it. Of course if you specify -w A on the command line, then you get all warnings, including the 'fragile pattern' warning. As regards defaults for warnings, here is more or less what I get on my ocaml installation. % ocamlc -v The Objective Caml compiler, version 3.09+dev11 (2004-11-30) % ocamlc -help ... -w Enable or disable warnings according to : A/a enable/disable all warnings ... E/e enable/disable fragile match ... default setting is "Aelz" -- Luc Maranget