caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] PV-GADTs
@ 2011-12-13 14:35 Dario Teixeira
  2011-12-13 15:00 ` Jacques Le Normand
  2011-12-14  2:56 ` Jacques Garrigue
  0 siblings, 2 replies; 5+ messages in thread
From: Dario Teixeira @ 2011-12-13 14:35 UTC (permalink / raw)
  To: caml

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 ]


Thanks in advance for your input!
Cheers,
Dario Teixeira


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] PV-GADTs
  2011-12-13 14:35 [Caml-list] PV-GADTs Dario Teixeira
@ 2011-12-13 15:00 ` Jacques Le Normand
  2011-12-13 19:15   ` Dario Teixeira
  2011-12-14  2:56 ` Jacques Garrigue
  1 sibling, 1 reply; 5+ messages in thread
From: Jacques Le Normand @ 2011-12-13 15:00 UTC (permalink / raw)
  To: Dario Teixeira; +Cc: caml

The way GADTs are handled is that local constraints are generated when
patterns are typed and then those constraints are used in the body of
the associated clause. To generate the constraints, we need to
propagate typing information. From my understanding, we can't do this
with polymorphic variants because it would change the typing
algorithm. In other words, with polymorphic variants the type of the
pattern is infered independently of the context.

From my understanding, Jacques Garrigue has good reasons to reject
propagation in such a case. Personally, I'd like to see a flag, say
-unsafepropagation, to let people use polymorphic variants and GADTs
at their own risk, knowing that the behaviour of the typing algorithm
may not satisfy some expected theoretical properties.


On Tue, Dec 13, 2011 at 9:35 AM, 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 ]
>
>
> Thanks in advance for your input!
> Cheers,
> Dario Teixeira
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] PV-GADTs
  2011-12-13 15:00 ` Jacques Le Normand
@ 2011-12-13 19:15   ` Dario Teixeira
  0 siblings, 0 replies; 5+ messages in thread
From: Dario Teixeira @ 2011-12-13 19:15 UTC (permalink / raw)
  To: Jacques Le Normand; +Cc: caml

Hi,

> The way GADTs are handled is that local constraints are generated when

> patterns are typed and then those constraints are used in the body of
> the associated clause. To generate the constraints, we need to
> propagate typing information. From my understanding, we can't do this
> with polymorphic variants because it would change the typing
> algorithm. In other words, with polymorphic variants the type of the
> pattern is infered independently of the context.
> 
> From my understanding, Jacques Garrigue has good reasons to reject
> propagation in such a case. Personally, I'd like to see a flag, say
> -unsafepropagation, to let people use polymorphic variants and GADTs
> at their own risk, knowing that the behaviour of the typing algorithm
> may not satisfy some expected theoretical properties.

Thanks for the clarification.  Mind you, my question did not stem from any
actual need for PV-GADTS; it was pure curiosity...

Cheers,
Dario


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] PV-GADTs
  2011-12-13 14:35 [Caml-list] PV-GADTs Dario Teixeira
  2011-12-13 15:00 ` Jacques Le Normand
@ 2011-12-14  2:56 ` Jacques Garrigue
  2011-12-14 15:12   ` Markus Mottl
  1 sibling, 1 reply; 5+ messages in thread
From: Jacques Garrigue @ 2011-12-14  2:56 UTC (permalink / raw)
  To: Dario Teixeira; +Cc: caml

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] PV-GADTs
  2011-12-14  2:56 ` Jacques Garrigue
@ 2011-12-14 15:12   ` Markus Mottl
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Mottl @ 2011-12-14 15:12 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: Dario Teixeira, caml

On Tue, Dec 13, 2011 at 21:56, Jacques Garrigue
<garrigue@math.nagoya-u.ac.jp> wrote:
> 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.

I really like using PVs for defining extensible, recursive DSLs.  If
it were possible to use GADTs in a similar way, that would be an
awesome feature.  But I wonder how this could be done cleanly.  I
agree that type inference would be impractical when combining PVs and
GADTs, since PV constructors are not tied to a specific type.

It seems you have something in particular in mind when you speak of
extensible GADTs.  Wouldn't such a feature require that GADTs have the
same runtime representation as PVs, i.e. using the hash value of the
variant name?  Not sure what the GADT representation is right now
anyway, but maybe this should be determined carefully before the next
release if we want to add extensibility later.

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-14 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-13 14:35 [Caml-list] PV-GADTs Dario Teixeira
2011-12-13 15:00 ` Jacques Le Normand
2011-12-13 19:15   ` Dario Teixeira
2011-12-14  2:56 ` Jacques Garrigue
2011-12-14 15:12   ` Markus Mottl

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).