From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id E60067ED5C for ; Mon, 6 Aug 2012 01:06:22 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=209.85.160.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of cedilla@gmail.com designates 209.85.160.54 as permitted sender) identity=mailfrom; client-ip=209.85.160.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pb0-f54.google.com) identity=helo; client-ip=209.85.160.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-pb0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqsBAAP8HlDRVaA2jWdsb2JhbABFgkqDMbM4CCIBAQEBCQkLCRIGI4IhAQEEEgIPBBkBGx4DDAYDAgs3AgIiAREBBQEcO4dbAQMMnG8JA4tUT4Jxg3sKGScNV4hxAQUMjyaCCoESA4hNjHyOLz6EHg X-IronPort-AV: E=Sophos;i="4.77,717,1336341600"; d="scan'208";a="152487457" Received: from mail-pb0-f54.google.com ([209.85.160.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Aug 2012 01:06:21 +0200 Received: by pbbrp2 with SMTP id rp2so296808pbb.27 for ; Sun, 05 Aug 2012 16:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=halqYorxhrMh6hbeQiP164vyQpUO3czBQgicG5S4WN8=; b=oSa+HsyMaZ2WdW+5dqRoHbny2WBY+f4c6z0NBv92qbYRIKrmMdO4wYzIix7RaboFKM JDXh7zMOxlhdhrTVpVkmOV9I7vRkGlE9BV9AcrhTywpBEizBiT3xVLJaLNtSkiYWWI91 8Al6kZkdBF8BmhzB7l5DS3fKpwr5nG6grpZduJ2pTNyuf21nTxqCANZxcYXmHMi22UVq 0oQBVq12POahu2+SI8zA2BvvhNF0j9wUTxaiTJdp9xc2kb3ZF6npT977S9GgPnoxIuER FgZNAHzPfRTQGxwaJMEcKuL4sIbhy/OzHFQmblufcrt0lxLznLwbQDKdVyhVkaJhpzeE FYog== MIME-Version: 1.0 Received: by 10.66.88.198 with SMTP id bi6mr14098315pab.23.1344207980085; Sun, 05 Aug 2012 16:06:20 -0700 (PDT) Received: by 10.142.173.15 with HTTP; Sun, 5 Aug 2012 16:06:19 -0700 (PDT) In-Reply-To: References: Date: Sun, 5 Aug 2012 16:06:19 -0700 Message-ID: From: Reed Wilson To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f46d042de42328423f04c68ccf9d X-Validation-by: cedilla@gmail.com Subject: Re: [Caml-list] creating GADTs --f46d042de42328423f04c68ccf9d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 =3D | 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 =3D 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 =3D 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? --=20 =C3=A7 --f46d042de42328423f04c68ccf9d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I think I've gotten everything pretty much straightened out now, but th= ere 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 =3D
| 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 = =3D 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 = =3D function
| S48000 -> 1152
| S44100 -> 1152
| S24000 -> 576
| S22050 -> 576

even though S48000 and S44100 are the exact same type! OCaml co= mplains:
Error: This pattern matches values of type mpeg1_t samplerate_t
=C2=A0 =C2=A0 =C2=A0 =C2=A0but a pattern was expected which matche= s values of type
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id 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 he= re. Is there any way to tell the typing system to let me combine the branch= es?

--
=C3=A7
--f46d042de42328423f04c68ccf9d--