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 F19F77ED5C for ; Tue, 7 Aug 2012 06:19:10 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jacques.garrigue@gmail.com) identity=pra; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="jacques.garrigue@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of jacques.garrigue@gmail.com designates 209.85.214.182 as permitted sender) identity=mailfrom; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="jacques.garrigue@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-ob0-f182.google.com) identity=helo; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="postmaster@mail-ob0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQCANaWIFDRVda2k2dsb2JhbABFqDyRDQgiAQEBAQkJCwkUBCOCIQEBBBICExkBOAEDDAEFBQQHAzghARIBBQEcBhMih1wDDJxcCQOPFIVlJw1KiH4BBQyKV4dUA4hLiyuBU4sJgyY+gVSCOQ X-IronPort-AV: E=Sophos;i="4.77,724,1336341600"; d="scan'208";a="152571918" Received: from mail-ob0-f182.google.com ([209.85.214.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 07 Aug 2012 06:19:09 +0200 Received: by obbun3 with SMTP id un3so11859184obb.27 for ; Mon, 06 Aug 2012 21:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=bT1B07TkYQjYzcI2+KpKzgBPZx+czMvrkJf8ZLi/XkE=; b=nVCAnoZADj6DCDEXoLarlCTsrkurpnCLhqVVWs1y4G6QYgMbCzYG+GZqUgFDENa0FI 0Pd4UEZM4TGV8PU6RQn89GQd7Lfu8OgaiN/5n88W4DAdEXBfusPOofkV4+B+190yr9Zl X4vg5qzh+14x5kvq5/2QsN7uN1RBlrWJXeUknJumEomOIYfcofGMe2/PsMbSnSPU2Gb5 1tOEAHu0/lrlCh4rvGFlAyp5S11YsRpei0He9Oplxit/lIScYlfInDOKtu5GE1K+wnru JkpYbxS6CPyo7MGUneBxnntg6yJThgsvskdfo2vifNqPAC9+LKTxyYjJak+k5N1+/IdY vB9A== MIME-Version: 1.0 Received: by 10.60.19.232 with SMTP id i8mr22530847oee.35.1344313148588; Mon, 06 Aug 2012 21:19:08 -0700 (PDT) Sender: jacques.garrigue@gmail.com Received: by 10.182.39.231 with HTTP; Mon, 6 Aug 2012 21:19:08 -0700 (PDT) Received: by 10.182.39.231 with HTTP; Mon, 6 Aug 2012 21:19:08 -0700 (PDT) In-Reply-To: References: Date: Tue, 7 Aug 2012 13:19:08 +0900 X-Google-Sender-Auth: vTmNMLtXSUHBtvD40tAkJObwvL8 Message-ID: From: Jacques Garrigue To: Reed Wilson Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=e89a8ff1c5a8b0424b04c6a54b4d Subject: Re: [Caml-list] creating GADTs --e89a8ff1c5a8b0424b04c6a54b4d Content-Type: text/plain; charset=ISO-8859-1 2012/08/06 1:11 "Reed Wilson" : > > 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 --e89a8ff1c5a8b0424b04c6a54b4d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

2012/08/06 1:11 "Reed Wilson" <cedilla@gmail.com>:
>
> I think I've gotten everything pretty much straightened out now, b= ut 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 functio= n
> | 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 functio= n
> | 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
> =A0 =A0 =A0 =A0but a pattern was expected which matches values of type=
> =A0 =A0 =A0 =A0 =A0id samplerate_t

The error message is not very clear, but the real cause is that currentl= y 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

--e89a8ff1c5a8b0424b04c6a54b4d--