caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Reed Wilson <cedilla@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] creating GADTs
Date: Tue, 7 Aug 2012 13:19:08 +0900	[thread overview]
Message-ID: <CA+p7B-zPEKp75-OVnqUE-yhOg70GxmtENYq3=e251kTYsRkYdQ@mail.gmail.com> (raw)
In-Reply-To: <CALLFq5RBXfwKjqMNSfE-0s5yorWftbLUv_57iAZe4qwfT4vnQg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]

2012/08/06 1:11 "Reed Wilson" <cedilla@gmail.com>:
>
> I think I've gotten everything pretty much straightened out now, but
there is something I didn't expect with GADTs and pattern-matching. Using
my previous samplerate_t type:
>
> type mpeg1_t
> type mpeg2_t
> type _ samplerate_t =
> | S48000 : mpeg1_t samplerate_t
> | S44100 : mpeg1_t samplerate_t
> | S24000 : mpeg2_t samplerate_t
> | S22050 : mpeg2_t samplerate_t
>
>
> I can't seem to do something like this:
>
> let samples_per_frame : type id. id samplerate_t -> int = function
> | S48000 | S44100 -> 1152
> | S24000 | S22050 -> 576
>
>
> Instead I have to have each of the constructors use a separate branch:
>
> let samples_per_frame : type id. id samplerate_t -> int = function
> | S48000 -> 1152
> | S44100 -> 1152
> | S24000 -> 576
> | S22050 -> 576
>
>
> even though S48000 and S44100 are the exact same type! OCaml complains:
> Error: This pattern matches values of type mpeg1_t samplerate_t
>        but a pattern was expected which matches values of type
>          id samplerate_t

The error message is not very clear, but the real cause is that currently
it is prohibited to generate GADT constraints in or-patterns.
One would have to check that the generated constraints are identical, which
is not possible at this point.
Future work...

Jacques Garrigue

[-- Attachment #2: Type: text/html, Size: 1708 bytes --]

      reply	other threads:[~2012-08-07  4:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-04  7:56 Reed Wilson
2012-08-04  9:21 ` Leo P White
     [not found]   ` <CALLFq5SWTGDuS5-Z7aN_UOqtTJ0sMvghWQTGqXUshUURiOoWcg@mail.gmail.com>
2012-08-04 22:52     ` Reed Wilson
2012-08-04 23:31       ` Gabriel Scherer
2012-08-04 23:45       ` Gabriel Scherer
2012-08-05  2:47         ` Reed Wilson
2012-08-05 23:06           ` Reed Wilson
2012-08-07  4:19             ` Jacques Garrigue [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='CA+p7B-zPEKp75-OVnqUE-yhOg70GxmtENYq3=e251kTYsRkYdQ@mail.gmail.com' \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=cedilla@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).