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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 9B5597FBFE for ; Fri, 23 Jan 2015 07:53:52 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jordojw@gmail.com) identity=pra; client-ip=209.85.215.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jordojw@gmail.com"; x-sender="jordojw@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of jordojw@gmail.com designates 209.85.215.45 as permitted sender) identity=mailfrom; client-ip=209.85.215.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jordojw@gmail.com"; x-sender="jordojw@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-la0-f45.google.com) identity=helo; client-ip=209.85.215.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jordojw@gmail.com"; x-sender="postmaster@mail-la0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiECAOvuwVTRVdctlGdsb2JhbABag1hYBIJ8wV+Ba4U2OYENB0MBAQEBAREBAQEBBwsLCRIwhA4EExEdARseAxIDBgc3AiQBEQEFASI1h3UBAwkIDaEWjSSDKz4xiy6Ba4J3ij4KGScNVIQRDBoBBQ6PZoJzgUEFigCDBoUqg1iBd4EkJoh7ggCEJhIjgQwJhDEdMQWCPgEBAQ X-IPAS-Result: AiECAOvuwVTRVdctlGdsb2JhbABag1hYBIJ8wV+Ba4U2OYENB0MBAQEBAREBAQEBBwsLCRIwhA4EExEdARseAxIDBgc3AiQBEQEFASI1h3UBAwkIDaEWjSSDKz4xiy6Ba4J3ij4KGScNVIQRDBoBBQ6PZoJzgUEFigCDBoUqg1iBd4EkJoh7ggCEJhIjgQwJhDEdMQWCPgEBAQ X-IronPort-AV: E=Sophos;i="5.09,453,1418079600"; d="scan'208";a="118261594" Received: from mail-la0-f45.google.com ([209.85.215.45]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jan 2015 07:53:52 +0100 Received: by mail-la0-f45.google.com with SMTP id gd6so5702840lab.4 for ; Thu, 22 Jan 2015 22:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=taL8+HbEYyE3w4ok1r5K0T8PVeic8Bi/HGSShdDFCNc=; b=FMqalP0D7DhpkZDji6LcfTf7LZgcilXSkKm6x7Nlop9DE4WP1rc+nbLVOruSXutLPb SSsML4RZAumOhLxBeTlJJY3TtANwT6POAIlWhN9tDG9g0U9qukjJ1YAPfjLH5m0GUupx k41+0ytSFcPzJ2DkxGYqL/V/lkxjq+HFDoOekwrT9CE21aB8a5fB9poIafvmdaCw2DyV xlg7Z7zrmKhCLzc75i49OMHxbClMZ8n4UhHO/r+jxntbM8o8Pg/8IxsfmC7+4Z5uaMMA WaAYaZT/7vvd+q0S3kognrBdeROgcoWQJe4c8YF7hfx3rf6vRhrN6OnU5hFvaDkGT79t 8Q+A== MIME-Version: 1.0 X-Received: by 10.152.8.104 with SMTP id q8mr5661792laa.56.1421996031157; Thu, 22 Jan 2015 22:53:51 -0800 (PST) Received: by 10.25.143.207 with HTTP; Thu, 22 Jan 2015 22:53:51 -0800 (PST) Date: Thu, 22 Jan 2015 22:53:51 -0800 Message-ID: From: Jordan W To: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=001a11c311984f2a29050d4c40eb X-Validation-by: jordojw@gmail.com Subject: [Caml-list] Explicit Arity with Polymorphic Variants --001a11c311984f2a29050d4c40eb Content-Type: text/plain; charset=UTF-8 The OCaml compiler allows distinguishing between variants that accept a single tuple and variant types that accept several parameters. What looks like a variant type accepting a tuple, is actually the later: type x = TwoSeparateArguments of int * int let tuple = (10,10) let thisWontWork = TwoSeparateArguments tuple;; >> Error: The constructor TwoSeparateArguments expects 2 argument(s), but is applied here to 1 argument(s) (* Notice the extra parens around the two ints *) type x = OneArgumentThatIsATuple of (int * int) let thisActuallyWorks = OneArgumentThatIsATuple tuple The extra parens distinguish at type definition time which of the two is intended. But OCaml does some automatic massaging of the data that you supply to constructor values. let _ = OneArgumentThatIsATuple (4, 5) let _ = TwoSeparateArguments (4, 5) No extra parens are required in this case. But OCaml does give you the ability to annotate patterns and expressions with an "explicit_arity" attribute which allows syntactic distinction between supplying two separate parameters vs. one that happens to be a tuple. This is important for other parser extensions that wish to treat the two distinctly. What OCaml allows (explicit_arity attribute) works well enough. The only problem is that there doesn't seem to be a way to utilize the same explicit_arity attributes with polymorphic variants. Such attributes are not acknowledged by the type system. Is this intended? Taking a quick look at typecore.ml, explicit_arity appears to be acknowledged on standard constructors but not polymorphic variants. https://github.com/ocaml/ocaml/blob/6e85c2d956c8fd5b45acd70a27586e44bb3a3119/typing/typecore.ml It seems these should be brought to consistency. I will file a mantis issue unless anyone believes this is intended. Thank you in advance. Jordan --001a11c311984f2a29050d4c40eb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The OCaml compiler allows distinguishing between variants = that accept a single tuple and variant types that accept several parameters= . What looks like a variant type accepting a tuple, is actually the later:<= div>
type x =3D TwoSeparateArguments of int * int
let tuple =3D (10,10)
let thisWontWork =3D TwoSeparat= eArguments tuple;;
>> Error: The constructor TwoSeparateArg= uments expects 2 argument(s), =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0but is applied here to 1 argument(s)<= /div>

(* Notice the extra parens around the two in= ts *)
type x =3D OneArgumentThatIsATuple of (int * int)
<= /div>
let thisActuallyWorks =3D OneArgumentThatIsATuple tuple

The extra parens distinguish at type definition time = which of the two is intended.

But OCaml does some = automatic massaging of the data that you supply to constructor values.
let _ =3D OneArgumentThatIsATuple (4, 5)
le= t _ =3D=C2=A0TwoSeparateArguments=C2=A0(4, 5)

No extra parens are required in this case. But OCaml does give you the ab= ility to annotate patterns and expressions with an "explicit_arity&quo= t; attribute which allows syntactic distinction between supplying two separ= ate parameters vs. one that happens to be a tuple. This is important for ot= her parser extensions that wish to treat the two distinctly. What OCaml all= ows (explicit_arity attribute) works well enough.

= The only problem is that there doesn't seem to be a way to utilize the = same explicit_arity attributes with polymorphic variants. Such attributes a= re not acknowledged by the type system. Is this intended?
Taking a quick look at typecore.= ml, explicit_arity appears to be acknowledged on standard constructors = but not polymorphic variants.

It seems these should b= e brought to consistency. I will file a mantis issue unless anyone believes= this is intended.

Thank you in advance.

Jordan


--001a11c311984f2a29050d4c40eb--