caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for feedback: A problem with injectivity and GADTs
Date: Sun, 28 Apr 2013 19:28:24 +0900	[thread overview]
Message-ID: <0F60A861-8DC4-41C8-98FA-B86FF53A4D39@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAP_800pUabwNwaDGUcf9jOHeAKSY9emeev77DJtJHAx_cbqEYA@mail.gmail.com>

On 2013/04/28, at 11:45, Markus Mottl <markus.mottl@gmail.com> wrote:

> On Sat, Apr 27, 2013 at 8:02 PM, Jacques Garrigue
> <garrigue@math.nagoya-u.ac.jp> wrote:
>> The fix is simple enough: we should track injectivity, and assume that abstract
>> types are not injective by default.
>> However, this also means that the first type I defined above (using Hashtbl.t)
>> will be refused.
> 
> If I understand your proposal correctly, the first type would only be
> refused unless the standard Hashtbl module were updated with
> appropriate injectivity annotations.  The type variables in the GADT
> would not need any annotations, because it is assumed that they have
> to be injective there anyway for soundness.

Yes, only abstract types need to be annotated.
Injectivity only makes sense for type aliases and abstract types (and private row types,
which hide an abstract type), since concrete types are always injective. For instance,
   type 'a t = T of int
is injective (you cannot unify  int t with bool t).

>> How many of you are using GADTs in this way, and how dependent are you on
>> abstract types ?
> 
> This seems like a "one percenter" problem.  OTOH, I guess most people
> also rarely run into problems where variance annotations matter, but
> if they do, they have no option.  The question should therefore rather
> be: what's the alternative?  Are there workarounds?  If not,
> annotations may just be a necessity to support advanced use cases.

At this point I think very few people are concerned.
So it might be the case that we could delay injectivity annotations until 4.02.
However, there is no easy workaround for abstract types.
The simplest one I can think of is duplicating types:

   type ('a,'b) t_impl
   type ('a, 'b) = Hashtbl of ('a,'b) t_impl

>> If we need to be able to define GADTs relying on the injectivity of some abstract
>> types, a straightforward solution is to add injectivity annotations on type parameters,
>> the same way it was done for variance:
>> 
>>  type #'a t
>> 
>> would mean that t is injective.
> 
> Seems concise, but I'm just a little worried that we may be raising
> the bar for beginners again.  The standard library would have to be
> updated with another annotation that may seem as obscure to beginners
> as variance annotations.  I hope we'll never have to explain to a
> beginner the meaning of $%^&#-'a.  Maybe a more verbose type
> constraint language would have been the better design choice here, but
> I guess we've already left this path with variance annotations.

As Jacques Le Normand pointed, injectivity is a property of parameters,
not of the whole type. (But in most cases a type is injective in all its parameters).

The addition of hard to read information is indeed the main drawback.
The fortunate part here is that, as long as you don't use GADTs, you need not
understand the meaning.

>> If you are curious about other difficulties of GADTs, the is also branches/abstract-new
>> which introduces a notion of new types, either concrete or abstract, which are guaranteed
>> to be distinct from each other, and any other concrete type. This is useful when
>> checking the exhaustiveness of pattern-matching, as we can then discard impossible
>> branches. That branch is completely experimental.
> 
> I haven't looked at this feature yet, but would this require even more
> annotations in the standard library?  If so, maybe it would indeed be
> time to think about a more accessible syntax for type constraints.

This is not really a replacement, since the requirements to be "new" are rather
restrictive. However, as a new type is automatically injective in all its parameters,
you would never need to make its injectivity explicit.
But we need indeed to think about the syntax.
All the more as other features, like the addition of runtime type information,
may also require annotations on types.

	Jacques


  reply	other threads:[~2013-04-28 10:28 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 [this message]
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
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=0F60A861-8DC4-41C8-98FA-B86FF53A4D39@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=markus.mottl@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).