caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Sebastien Mondet <sebastien.mondet@gmail.com>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Propagating types to pattern-matching
Date: Tue, 12 Feb 2013 11:28:39 +0900	[thread overview]
Message-ID: <0B8A0D3C-CB7E-4B37-8386-F05B81E416C0@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CALScVYmE+d88QaR27eU=FmFk+UJYZAE9NuQUmWeH9AocE8RZqA@mail.gmail.com>

On 2013/02/12, at 0:31, Sebastien Mondet <sebastien.mondet@gmail.com> wrote:

> Hi Jacques
> 
> I don't know if this directly related, or if it is actually intended, but this looks like a regression to me:
> 
> 
> With OCaml version 4.00.1+dev2_2012-08-06  (4.00.1+short-types in Opam):
> 
> # let f = function 0 -> `zero | 1 -> `one | _ -> `some;;
> val f : int -> [> `one | `some | `zero ] = <fun>
> 
> # let g x = match f x with `one -> 1 | `zero -> 0;;
> Error: This pattern matches values of type [< `one | `zero ]
>        but a pattern was expected which matches values of type
>          [> `one | `some | `zero ]
>        The first variant type does not allow tag(s) `some
> 
> which is the nice behavior we were used to,
> but with OCaml version 4.01.0+dev10-2012-10-16  (a.k.a.  4.01.0dev+short-paths), the error has been downgraded to a warning:
> 
> # let f = function 0 -> `zero | 1 -> `one | _ -> `some;;
> val f : int -> [> `one | `some | `zero ] = <fun>
> 
> # let g x = match f x with `one -> 1 | `zero -> 0;;
> Warning 8: this pattern-matching is not exhaustive.
> Here is an example of a value that is not matched:
> `some
> val g : int -> int = <fun>
> 

This is related, and this is the intended behavior.
For polymorphic variants, you get a warning if the type was known early enough,
and a hard error otherwise.
Actually, I see it as a progress, since the warning gives you a counter-example,
whereas the error message only gives you a discrepancy between types.

For me the only sane handling of partial matching is to see it as an error,
so use at least -warn-error P. (Or at least watch for warnings)

	Jacques Garrigue



      parent reply	other threads:[~2013-02-12  2:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15  5:59 Jacques Garrigue
2013-02-11 15:31 ` Sebastien Mondet
2013-02-12  1:44   ` Jacques Le Normand
2013-02-12  2:28   ` Jacques Garrigue [this message]

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=0B8A0D3C-CB7E-4B37-8386-F05B81E416C0@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=sebastien.mondet@gmail.com \
    /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).