caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: luc.maranget@inria.fr (Luc Maranget)
To: Alex Baretta <alex@barettadeit.com>
Cc: Ocaml <caml-list@inria.fr>, Luc Maranget <luc.maranget@inria.fr>
Subject: Re: [Caml-list] Fragile pattern matching?!
Date: Mon, 28 Feb 2005 11:39:59 +0100	[thread overview]
Message-ID: <20050228103959.GA31015@yquem.inria.fr> (raw)
In-Reply-To: <4222EF9E.1030106@barettadeit.com>

> 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 <flags>  Enable or disable warnings according to <flags>:
     A/a enable/disable all warnings
     ...
     E/e enable/disable fragile match
     ...
     default setting is "Aelz"


-- Luc Maranget


  parent reply	other threads:[~2005-02-28 10:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-28 10:17 Alex Baretta
2005-02-28 10:32 ` [Caml-list] " Keith Wansbrough
2005-02-28 10:35   ` Alex Baretta
2005-02-28 10:39 ` Luc Maranget [this message]
2005-02-28 10:49   ` Alex Baretta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050228103959.GA31015@yquem.inria.fr \
    --to=luc.maranget@inria.fr \
    --cc=alex@barettadeit.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).