caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Reed Wilson <cedilla@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] creating GADTs
Date: Sun, 5 Aug 2012 16:06:19 -0700	[thread overview]
Message-ID: <CALLFq5RBXfwKjqMNSfE-0s5yorWftbLUv_57iAZe4qwfT4vnQg@mail.gmail.com> (raw)
In-Reply-To: <CALLFq5TCFtHE9TdsOJOPu4kd+Jf+BQEsbsrg_78ymfB51iE7wA@mail.gmail.com>

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

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


I certainly don't know a lot about these new type features, but I know
there shouldn't be a limitation in what I'm doing with them here. Is there
any way to tell the typing system to let me combine the branches?

-- 
ç

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

  reply	other threads:[~2012-08-05 23:06 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 [this message]
2012-08-07  4:19             ` Jacques Garrigue

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=CALLFq5RBXfwKjqMNSfE-0s5yorWftbLUv_57iAZe4qwfT4vnQg@mail.gmail.com \
    --to=cedilla@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;
as well as URLs for NNTP newsgroup(s).