caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] PV-GADTs
Date: Wed, 14 Dec 2011 11:56:20 +0900	[thread overview]
Message-ID: <CA+p7B-zqC5Sm9wtiK6kR3O7BJ=w365dufRf_q1-dryb7UgR5qg@mail.gmail.com> (raw)
In-Reply-To: <1323786905.94413.YahooMailNeo@web111503.mail.gq1.yahoo.com>

On Tue, Dec 13, 2011 at 11:35 PM, Dario Teixeira
<darioteixeira@yahoo.com> wrote:
> Hi,
> I wonder, is there any theoretical reason why GADTs cannot be associated with
> polymorphic variants?  As an example, consider the two type declarations below.
> The first is your run-of-the-mill GADT, supported by the current SVN trunk.  The
> second is a PV-GADT, which is not accepted.  But is this just a present limitation
> or a fundamental one?
>
> type _ t1 = Foo: int t1 | Bar: float t1
>
> type _ t2 = [ `Foo: int t2 | `Bar: float t2 ]

Actually, Jacques Le Normand didn't directly answer your question.
He just explained why we cannot currently combine polymorphic variants
and GADTs in the same pattern-matching.
This could be improved if the need is clear.

However what you are asking for is different: you want indexed
polymorphic variants.
But there the problem is more fundamental.
The strength of polymorphic variants is that you don't have to define them.
But if you don't relate the constructors to a specific type, there is
no way you can
constrain the index.
In your example, how do you know in a pattern-matching that `Foo comes from t2?
Type inference could be used, but I'm afraid it would be very fragile,
and  not easy to use.
So at this point there is no plan to add GADT PVs.

An alternative design would be to have extensible GADTs, where you would be able
to add new cases, like for exn.
I think this would be useful, and cover some uses that are not
possible even with PVs.

Jacques Garrigue


  parent reply	other threads:[~2011-12-14  2:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13 14:35 Dario Teixeira
2011-12-13 15:00 ` Jacques Le Normand
2011-12-13 19:15   ` Dario Teixeira
2011-12-14  2:56 ` Jacques Garrigue [this message]
2011-12-14 15:12   ` Markus Mottl

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='CA+p7B-zqC5Sm9wtiK6kR3O7BJ=w365dufRf_q1-dryb7UgR5qg@mail.gmail.com' \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=darioteixeira@yahoo.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).