caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: Alain Frisch <alain@frisch.fr>, OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for feedback: A problem with injectivity and GADTs
Date: Tue, 30 Apr 2013 11:11:49 +0200	[thread overview]
Message-ID: <CAPFanBHEReUEhczHQBz7+y3w02Zk_2SFCq3K-2E+0a8uTgFkYQ@mail.gmail.com> (raw)
In-Reply-To: <1D6C7417-8F98-4979-B6AF-E8C10CC21F71@math.nagoya-u.ac.jp>

> The only other thing it does is a slight strengthening of variance checking.
>
> Consider the type
>    type 'a t = T                   (* 'a bi-variant and injective *)
>    type 'a u = 'a t -> 'a t    (* 'a t occurs both at positive and negative positions *)
>
> Originally, the parameter of u would have been bi-variant (or unrestricted)
> since it is bi-variant in the definition of t.
> However it is now invariant.
> The reason is that you can only change it by subtyping in t, and u doesn't allow subtyping.
> This is a reasonable restriction, and it is necessary to allow some GADT
> definitions where we use concrete types as indices.

I'm not sure about this. In our work on variance of GADTs (
http://arxiv.org/abs/1301.2903 ), we defined equality exactly as the
antisymmetric closure of the subtyping relation (as is done in the
previous work by Simonet and Pottier), and all type constructors are
functional: (a = b) implies (a t = b t). This means that in our
formalization, you ('a u = 'a bivar -> 'a bivar) is bivariant, because
('a bivar = 'b bivar) for any 'a and 'b implies (a u = 'a bivar -> 'a
bivar = 'b bivar -> 'b bivar = 'b u).

This vision of invariance as still functional also plays nicely with
the inversion principle: when you have (a t <= b t) when t covariant,
you can deduce (a <= b), when t is contravariant you have (a >= b),
and we can explain invariance as saying that you then have both, (a <=
b) and (b <= a), which coincides with the algorithmic notion of
"occurs both negatively and positively". The nice thing is that this
inversion criterion is also complete, from (a <= b) and (b <= a) you
can deduce (a t <= b t) for t invariant (in our system).

What is the reason for adding your strengthening? What I understood so
far is that unification, and therefore provable equality/inequalities,
were orthogonal to variance (eg. (type 'a t = T) is both bivariant and
injective). Is there a reason to tie them back together precisely in
the invariant case?

On Tue, Apr 30, 2013 at 10:18 AM, Jacques Garrigue
<garrigue@math.nagoya-u.ac.jp> wrote:
> On 2013/04/30, at 17:02, Alain Frisch <alain@frisch.fr> wrote:
>
>> On 04/30/2013 09:56 AM, Jacques Garrigue wrote:
>>> On 2013/04/30, at 15:59, Alain Frisch <alain@frisch.fr> wrote:
>>>
>>>> It's reassuring to see that the conservative solution (not assuming injectivity of user defined abstract types) does not seem too bad for now, even if not very satisfying.
>>>>
>>>> I'm only concerned with:
>>>>
>>>>> 3) The problem I describe in my first mail. I.e. when defining a type,
>>>>>   if you use type variables appearing in constrained type parameters,
>>>>>   you need the type constructors leading to the type variables to be
>>>>>   injective. This is PR#5985, and it is only fixed in branches/non-vanishing.
>>>>
>>>> Do you think that fixing this unsoundness (without injectivity annotations) would lead to reject existing programs?
>>>
>>> Potentially yes.
>>> But I don't know how it is in practice for code existing now.
>>> Hence my question.
>>
>> Apart from GADTs, does your patch address the unsoundness with type constraints?
>
> Sure, this is exactly the same mechanism.
>
> The only other thing it does is a slight strengthening of variance checking.
>
> Consider the type
>    type 'a t = T                   (* 'a bi-variant and injective *)
>    type 'a u = 'a t -> 'a t    (* 'a t occurs both at positive and negative positions *)
>
> Originally, the parameter of u would have been bi-variant (or unrestricted)
> since it is bi-variant in the definition of t.
> However it is now invariant.
> The reason is that you can only change it by subtyping in t, and u doesn't allow subtyping.
> This is a reasonable restriction, and it is necessary to allow some GADT
> definitions where we use concrete types as indices.
>
> 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

  reply	other threads:[~2013-04-30  9:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-28  0:02 Jacques Garrigue
2013-04-28  2:45 ` Markus Mottl
2013-04-28 10:28   ` Jacques Garrigue
2013-04-28  5:54 ` Jacques Le Normand
2013-04-29  3:45 ` Ivan Gotovchits
2013-04-29  4:03   ` Ivan Gotovchits
2013-04-29  5:17 ` Jacques Le Normand
2013-04-29  7:58   ` Alain Frisch
2013-04-29 10:52     ` Jacques Garrigue
2013-04-29 11:23       ` Alain Frisch
2013-04-29 16:37         ` Nathan Mishra Linger
2013-04-29 23:53           ` Jacques Garrigue
2013-04-30  5:45       ` Jacques Garrigue
2013-05-04  6:46         ` Jacques Garrigue
2013-05-04  7:09           ` Gabriel Scherer
2013-05-04 12:28             ` Jacques Garrigue
2013-04-30  6:59       ` Alain Frisch
2013-04-30  7:56         ` Jacques Garrigue
2013-04-30  8:02           ` Alain Frisch
2013-04-30  8:18             ` Jacques Garrigue
2013-04-30  9:11               ` Gabriel Scherer [this message]
2013-04-30  9:55                 ` Jacques Garrigue
2013-04-30 10:12                   ` Leo White
2013-04-30 11:30                     ` Gabriel Scherer
2013-04-30 13:06                       ` Leo White
2013-04-29  7:59   ` Gabriel Scherer
2013-07-01 14:47 ` Alain Frisch
2013-07-01 23:20   ` Jacques Garrigue
2013-07-03 16:08     ` Alain Frisch
2013-07-03 16:13       ` Gabriel Scherer
2013-07-04  6:07         ` [Caml-list] Request for feedback: A problem with injectivity oleg
2013-07-04  7:35           ` Alain Frisch
2013-07-05 10:30             ` oleg
2013-07-05 12:02               ` Alain Frisch
2013-07-04  1:00       ` [Caml-list] Request for feedback: A problem with injectivity and GADTs Jacques Garrigue
2013-07-04  8:14         ` Alain Frisch
2013-07-04  8:52           ` Jacques Garrigue

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=CAPFanBHEReUEhczHQBz7+y3w02Zk_2SFCq3K-2E+0a8uTgFkYQ@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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).