From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 1C2857F20B for ; Tue, 12 Feb 2013 02:44:38 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rathereasy@gmail.com) identity=pra; client-ip=209.85.219.54; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rathereasy@gmail.com"; x-sender="rathereasy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rathereasy@gmail.com designates 209.85.219.54 as permitted sender) identity=mailfrom; client-ip=209.85.219.54; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rathereasy@gmail.com"; x-sender="rathereasy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oa0-f54.google.com) identity=helo; client-ip=209.85.219.54; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rathereasy@gmail.com"; x-sender="postmaster@mail-oa0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0BAC+dGVHRVds2m2dsb2JhbAA+Bq43iUsBiR4IFg4BAQEBAQgJCwkUJ4IfAQEEAScZARsSCwEDDAYFCw0NISEBAREBBQEKEgYTEodtAQMJBgyiDIw0gnuEOAoZJwMKWYh8AQUMjDOBHoQwA4hmi2WBWYEdiiODMRYphEo X-IPAS-Result: Av0BAC+dGVHRVds2m2dsb2JhbAA+Bq43iUsBiR4IFg4BAQEBAQgJCwkUJ4IfAQEEAScZARsSCwEDDAYFCw0NISEBAREBBQEKEgYTEodtAQMJBgyiDIw0gnuEOAoZJwMKWYh8AQUMjDOBHoQwA4hmi2WBWYEdiiODMRYphEo X-IronPort-AV: E=Sophos;i="4.84,646,1355094000"; d="scan'208";a="2401531" Received: from mail-oa0-f54.google.com ([209.85.219.54]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 12 Feb 2013 02:44:37 +0100 Received: by mail-oa0-f54.google.com with SMTP id n12so7059876oag.13 for ; Mon, 11 Feb 2013 17:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=MNgblaBuCj4ClJaEg4eFga9NAeidKC7YZLiq9HJOdpg=; b=gB3/jccAoC2zFQnh9TDAtqWTuo157mZq5s7GtwLOKx6/e2UaazCKI6jCCe3BZ/b5nH ITTOSOhl0buBOQOkDEEbIxRYURYrcaN/AfkC3Ii/RB113Degf9WjEHzK8PkxibLrbBZI 9YAt92+dhI9AjXT/MyK+D/MPbdRDl8MoAckwX9Y3c0ODGchAHEsgDCRg8tQQjSnVj5p3 ccsPsIzqkuzLpaqz7uWz8g2aUovO0CoDfYqIP3+aDICg+Kz4HUSBOvELFSJWraDUjRS9 0CqHesQD79dGEfuFZg+W/8gnOfzACCAiM9ppCltiD1e5vzWuGazZMIrzfArfq0fCXC7Z KNfQ== MIME-Version: 1.0 X-Received: by 10.182.54.102 with SMTP id i6mr12109542obp.67.1360633475657; Mon, 11 Feb 2013 17:44:35 -0800 (PST) Received: by 10.76.76.233 with HTTP; Mon, 11 Feb 2013 17:44:35 -0800 (PST) In-Reply-To: References: Date: Mon, 11 Feb 2013 17:44:35 -0800 Message-ID: From: Jacques Le Normand To: Sebastien Mondet Cc: "caml-list@inria.fr" , Jacques Garrigue Content-Type: multipart/alternative; boundary=14dae93a1145fc6fcf04d57d2a75 Subject: Re: [Caml-list] Propagating types to pattern-matching --14dae93a1145fc6fcf04d57d2a75 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable In this particular case those prudent enough to use '-warn-error -a' will get a more informative error message, which is nice. Furthermore, for those who think of polymorphic variants as an extension of variants, this makes more sense. On Mon, Feb 11, 2013 at 7:31 AM, 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 =3D function 0 -> `zero | 1 -> `one | _ -> `some;; > val f : int -> [> `one | `some | `zero ] =3D > > # let g x =3D 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 =3D function 0 -> `zero | 1 -> `one | _ -> `some;; > val f : int -> [> `one | `some | `zero ] =3D > > # let g x =3D 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 =3D > > > Is it intended? > > Cheers > Seb > > > > > > > > > > > > > > > > > > > > > > > On Tue, Jan 15, 2013 at 12:59 AM, Jacques Garrigue < > garrigue@math.nagoya-u.ac.jp> wrote: > >> Dear Camlers, >> >> It is a bit unusual, but this message is about changes in trunk. >> >> As you may be aware from past threads, since the introduction of GADTs >> in 4.00, some type information is propagated to pattern-matching, to all= ow >> it to refine types. >> More recently, types have started being used to disambiguate constructors >> and record fields, which means some more dependency on type information >> in pattern-matching. >> >> However, a weakness of this approach was that propagation was disabled >> as soon as a pattern contained polymorphic variants. The reason is that >> typing rules for polymorphic variants in patterns and expression are >> subtly >> different, and mixing information without care would lose principality. >> >> At long last I have removed this restriction on the presence of >> polymorphic >> variants, but this has some consequences on typing: >> >> * while type information is now propagated, information about possibly >> present constructors still has to be discarded. For instance this means >> that >> the following code will not be typed as you could expect: >> >> let f (x : [< `A | `B]) =3D match x with `A -> 1 | _ -> 2;; >> val f : [< `A | `B > `A ] -> int >> >> What happens is that inside pattern-matching, only required constructo= rs >> are propagated, which reduces the type of x to [> ] (a polymorphic >> variant >> type with any constructor=85) >> As before, to give an upper bound to the matched type, the type >> annotation >> must be inside a pattern: >> >> let f =3D function (`A : [< `A | `B]) -> 1 | _ -> 2;; >> val f : [< `A | `B ] -> int =3D >> >> * the propagation of type information may lead to failure in some cases >> that >> where typable before: >> >> type ab =3D [ `A | `B ];; >> let f (x : [`A]) =3D match x with #ab -> 1;; >> Error: This pattern matches values of type [? `A | `B ] >> but a pattern was expected which matches values of type [ >> `A ] >> The second variant type does not allow tag(s) `B >> >> During pattern-matching it is not allowed to match on absent type >> constructors, >> even though the type of the patterns would eventually be [< `A | `B], >> which allows >> discarding `B. ([? `A | `B] denotes a type obeying the rules of >> pattern-matching) >> >> * for the sake of coherence, even if a type was not propagated because it >> was not known when typing a pattern-matching, we are still going to >> fail if a >> matched constructor appears to be absent after typing the whole >> function. >> (This only applies to propagable types, i.e. polymorphic variant types >> that >> contain only required constructors) >> >> In particular the last two points are important, because previously such >> uses >> would not have triggered even a warning. >> >> The idea is that allowing propagation of types is more important than >> keeping some not really useful corner cases, but if this is of concern >> to you, I'm interested in feedback. >> >> Jacques Garrigue >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > > --14dae93a1145fc6fcf04d57d2a75 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable In this particular case those prudent enough to use '-warn-error -a'= ; will get a more informative error message, which is nice. Furthermore, fo= r those who think of polymorphic variants as an extension of variants, this= makes more sense.

On Mon, Feb 11, 2013 at 7:31 AM, Sebastien M= ondet <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 OCa= ml version 4.00.1+dev2_2012-08-06=A0 (4.00.1+short-types in Opam):

# let f =3D function 0 -> `zero | 1 -> `one | _ -> `some;;
= val f : int -> [> `one | `some | `zero ] =3D <fun>

# let= g x =3D match f x with `one -> 1 | `zero -> 0;;
Error: This patte= rn matches values of type [< `one | `zero ]

=A0=A0=A0=A0=A0=A0 but a pattern was expected which matches values of type<= br>
=A0=A0=A0=A0=A0=A0=A0=A0 [> `one | `some | `zero ]
=A0=A0=A0= =A0=A0=A0 The first variant type does not allow tag(s) `some

<= div>which is the nice behavior we were used to,
but with OCaml version 4.01.0+dev10-2012-10-16=A0 (a.k.a.=A0 4.01.0de= v+short-paths), the error has been downgraded to a warning:

# let f =3D function 0 -> `zero | 1 -> `one | _ -> `some;;
= val f : int -> [> `one | `some | `zero ] =3D <fun>

# let= g x =3D match f x with `one -> 1 | `zero -> 0;;
Warning 8: this p= attern-matching is not exhaustive.
Here is an example of a value that is not matched:
`some
val g : int = -> int =3D <fun>


Is it intended?

Che= ers
Seb






















On Tue, Jan 15, 2013 at 12:59 AM, Ja= cques Garrigue <garrigue@math.nagoya-u.ac.jp> wro= te:
Dear Camlers,

It is a bit unusual, but this message is about changes in trunk.

As you may be aware from past threads, since the introduction of GADTs
in 4.00, some type information is propagated to pattern-matching, to allow<= br> it to refine types.
More recently, types have started being used to disambiguate constructors and record fields, which means some more dependency on type information
in pattern-matching.

However, a weakness of this approach was that propagation was disabled
as soon as a pattern contained polymorphic variants. The reason is that
typing rules for polymorphic variants in patterns and expression are subtly=
different, and mixing information without care would lose principality.

At long last I have removed this restriction on the presence of polymorphic=
variants, but this has some consequences on typing:

* while type information is now propagated, information about possibly
=A0 present constructors still has to be discarded. For instance this means= that
=A0 the following code will not be typed as you could expect:

=A0 =A0 =A0 =A0 let f (x : [< `A | `B]) =3D match x with `A -> 1 | _ = -> 2;;
=A0 =A0 =A0 =A0 val f : [< `A | `B > `A ] -> int

=A0 What happens is that inside pattern-matching, only required constructor= s
=A0 are propagated, which reduces the type of x to [> ] (a polymorphic v= ariant
=A0 type with any constructor=85)
=A0 As before, to give an upper bound to the matched type, the type annotat= ion
=A0 must be inside a pattern:

=A0 =A0 =A0 =A0 let f =3D function (`A : [< `A | `B]) -> 1 | _ -> = 2;;
=A0 =A0 =A0 =A0 val f : [< `A | `B ] -> int =3D <fun>

* the propagation of type information may lead to failure in some cases tha= t
=A0 where typable before:

=A0 =A0 =A0 =A0 type ab =3D [ `A | `B ];;
=A0 =A0 =A0 =A0 let f (x : [`A]) =3D match x with #ab -> 1;;
=A0 =A0 =A0 =A0 Error: This pattern matches values of type [? `A | `B ]
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0but a pattern was expected which matches val= ues of type [ `A ]
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0The second variant type does not allow tag(s= ) `B

=A0 During pattern-matching it is not allowed to match on absent type const= ructors,
=A0 even though the type of the patterns would eventually be [< `A | `B]= , which allows
=A0 discarding `B. ([? `A | `B] denotes a type obeying the rules of pattern= -matching)

* for the sake of coherence, even if a type was not propagated because it =A0 was not known when typing a pattern-matching, we are still going to fai= l if a
=A0 matched constructor appears to be absent after typing the whole functio= n.
=A0 (This only applies to propagable types, i.e. polymorphic variant types = that
=A0 =A0contain only required constructors)

In particular the last two points are important, because previously such us= es
would not have triggered even a warning.

The idea is that allowing propagation of types is more important than
keeping some not really useful corner cases, but if this is of concern
to you, I'm interested in feedback.

=A0 =A0 =A0 =A0 Jacques Garrigue
--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
<= br>

--14dae93a1145fc6fcf04d57d2a75--