From: Ashish Agarwal <agarwal1975@gmail.com>
To: Leo White <lpw25@cam.ac.uk>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] OR-patterns with GADTs
Date: Sat, 22 Nov 2014 07:44:29 -0500 [thread overview]
Message-ID: <CAMu2m2KKqHYYuaw4rcvJL8_pT=PTb2MNUrenjcQP0K7PJ+qMog@mail.gmail.com> (raw)
In-Reply-To: <877fyoi7tb.fsf@study.localdomain>
[-- Attachment #1: Type: text/plain, Size: 1462 bytes --]
Thanks for the link to the Mantis issue.
On Fri, Nov 21, 2014 at 4:04 PM, Leo White <lpw25@cam.ac.uk> wrote:
> Ashish Agarwal <agarwal1975@gmail.com> writes:
>
> > The following works fine:
> >
> > type foo
> > type bar
> > type _ t =
> > | Foo : string -> foo t
> > | Bar : string -> bar t
> >
> > let to_string : type a . a t -> string = function
> > | Foo x -> x
> > | Bar x -> x
> >
> > However, if you try to avoid the redundant code of the two branches, you
> get a compile error:
> >
> > let to_string : type a . a t -> string = function
> > | Foo x
> > | Bar x -> x
> >
> > Error: This pattern matches values of type foo t
> > but a pattern was expected which matches values of type a t
> > Type foo is not compatible with type a
> >
> > Is there a real reason for this?
>
> I think the reason is that full support for or-patterns with GADTs is
> difficult. Matching on one GADT pattern generates one set of equations
> and matching on the other generates a different set of equations and you
> then need to check the body under the (parts of the) equations that are
> in both patterns. There might be something simpler than full support
> which wouldn't be that hard, but its not clear what that would be, so at
> the moment things just fail if you use GADTs in an or-pattern.
>
> There is a Mantis issue for it
> (http://caml.inria.fr/mantis/view.php?id=5736), so hopefully it will be
> resolved one day.
>
> Regards,
>
> Leo
>
[-- Attachment #2: Type: text/html, Size: 2154 bytes --]
prev parent reply other threads:[~2014-11-22 12:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-21 18:39 Ashish Agarwal
2014-11-21 21:04 ` Leo White
2014-11-22 12:44 ` Ashish Agarwal [this message]
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='CAMu2m2KKqHYYuaw4rcvJL8_pT=PTb2MNUrenjcQP0K7PJ+qMog@mail.gmail.com' \
--to=agarwal1975@gmail.com \
--cc=caml-list@inria.fr \
--cc=lpw25@cam.ac.uk \
/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