From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3GFOZN9009916 for ; Mon, 16 Apr 2012 17:24:35 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnIBAMc4jE/RVdQ2kGdsb2JhbABEhWatSQgiAQEBAQkJDQcUBCOCIgIPBBkBGx4DEgMGBzcCJAERAQUBV4ddAQMLmDaCXAqLUk6CcoQ9ChknDVeIdgEFC44aggyBGASVbY5VPYQm X-IronPort-AV: E=Sophos;i="4.75,428,1330902000"; d="scan'208";a="140401286" Received: from mail-vb0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Apr 2012 17:24:29 +0200 Received: by mail-vb0-f54.google.com with SMTP id v11so6703203vbm.27 for ; Mon, 16 Apr 2012 08:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=bDoQ6rXmE3T42VyXYBSeAsbW9gAA1XzNXlsAYMr1MuU=; b=Z48z+GI/SWqxDWIs9+j5yzxWFyp0PU90Naa/Q3apoZ8Gy6u6ds0VljYRDdKNEb49az 9qPPZPXl3ay8GOphTWINDvRbfxo/i149txfEFr+vfd8diC0JxlPHUcni6hjeHh0BI6Nx g3SjtVCOEPi9e5gjsom788GroJZDa4vz56luVGmwzRjYwLa6SsWILH8JjNS8x6uLBtdm 31AXjsxVyUUjXKAGfz5fg7iieg8VrovJMPrDcUuRqNtI3RlemzghWo0l9ej5oHyIcf50 zG7QFQqzoVVykUECTb4Z6hN8f5OKoIVd1RlkQ/UIMyd7DvqfEaP2qqTOGzhHJq7KOeBd Yh2Q== Received: by 10.52.37.102 with SMTP id x6mr5020649vdj.72.1334589869780; Mon, 16 Apr 2012 08:24:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.37.137 with HTTP; Mon, 16 Apr 2012 08:24:09 -0700 (PDT) From: Sebastien Mondet Date: Mon, 16 Apr 2012 11:24:09 -0400 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=20cf3079bb461bf09304bdcd6be1 Subject: [Caml-list] Potential Feature Request: "Remove poly-variants from match-with statements" --20cf3079bb461bf09304bdcd6be1 Content-Type: text/plain; charset=UTF-8 Hi I don't know if it is theoretically sound or possible, but it would be helpful, if the typing of match-with statements with polymorphic variants was able to remove one or more variants from the "catch-all" cases In the following code, it would mean that three_is_a_lot would be typed like three_is_a_lot_2 without having to write all the cases. # let how_much = function | 1 -> `One | 2 -> `Two | 3 -> `Three | n -> `A_lot;; val how_much : int -> [> `A_lot | `One | `Three | `Two ] = # let three_is_a_lot x = match how_much x with | `Three -> `A_lot | any -> any;; val three_is_a_lot : int -> [> `A_lot | `One | `Three | `Two ] = # let three_is_a_lot_2 x = match how_much x with | `Three -> `A_lot | `One | `Two | `A_lot as any -> any;; val three_is_a_lot_2 : int -> [> `A_lot | `One | `Two ] = The practical use-case for us is that we use polymorphic variants to encode "semantic" errors in an Error/Result monad. What does the list think? Cheers, Sebastien --20cf3079bb461bf09304bdcd6be1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi

I don't know if it is theoret= ically sound or possible, but
it would be helpful, if the typing = of match-with statements with polymorphic
variants was able to re= move one or more variants from the "catch-all" cases

In the following code, it would mean that three_is_a_lo= t would be typed like
three_is_a_lot_2 without having to write al= l the cases.


# let how_much =3D fun= ction
=C2=A0 | 1 -> `One
=C2=A0 | 2 -> `Two
=C2=A0= | 3 -> `Three
=C2=A0 | n -> `A_lot;;

<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 val how_much : int -> [> `A_lot | `On= e | `Three | `Two ] =3D <fun>

# let three_is_a_lot x =3D
=C2=A0 match how_m= uch x with
=C2=A0 | `Three -> `A_lot
=C2=A0 | any -&= gt; any;;

=C2=A0 =C2=A0 =C2=A0 val three_is_a_lot = : int -> [> `A_lot | `One | `Three | `Two ] =3D <fun>

# let three_is_a_lot_2 x =3D
=C2=A0 match how= _much x with
=C2=A0 | `Three -> `A_lot
=C2=A0 | `One= | `Two | `A_lot as any -> any;;

=C2=A0 =C2=A0 = =C2=A0 val three_is_a_lot_2 : int -> [> `A_lot | `One | `Two ] =3D &l= t;fun>


The practical use-case for us is t= hat we use polymorphic variants to encode "semantic" errors in an= Error/Result monad.

What does the list think?

Cheers,
Sebastien

--20cf3079bb461bf09304bdcd6be1--