caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Keith Wansbrough <Keith.Wansbrough@cl.cam.ac.uk>
To: Alex Baretta <alex@barettadeit.com>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Fragile pattern matching?!
Date: Mon, 28 Feb 2005 10:32:26 +0000	[thread overview]
Message-ID: <E1D5iCQ-0001qB-00@mta1.cl.cam.ac.uk> (raw)
In-Reply-To: Your message of "Mon, 28 Feb 2005 11:17:02 +0100." <4222EF9E.1030106@barettadeit.com>

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.

HTH.

--KW 8-)


  reply	other threads:[~2005-02-28 10:32 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 ` Keith Wansbrough [this message]
2005-02-28 10:35   ` [Caml-list] " Alex Baretta
2005-02-28 10:39 ` Luc Maranget
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=E1D5iCQ-0001qB-00@mta1.cl.cam.ac.uk \
    --to=keith.wansbrough@cl.cam.ac.uk \
    --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).