From: Leo White <lpw25@cam.ac.uk>
To: Ashish Agarwal <agarwal1975@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] OR-patterns with GADTs
Date: Fri, 21 Nov 2014 21:04:48 +0000 [thread overview]
Message-ID: <877fyoi7tb.fsf@study.localdomain> (raw)
In-Reply-To: <CAMu2m2K5Xy2nEdZb1uDC1U5NS2rDRCjx5rnPegyK=o98xgEW8g@mail.gmail.com> (Ashish Agarwal's message of "Fri, 21 Nov 2014 13:39:09 -0500")
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
next prev parent reply other threads:[~2014-11-21 20:48 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 [this message]
2014-11-22 12:44 ` Ashish Agarwal
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=877fyoi7tb.fsf@study.localdomain \
--to=lpw25@cam.ac.uk \
--cc=agarwal1975@gmail.com \
--cc=caml-list@inria.fr \
/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