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 F1BD47F8FC for ; Mon, 9 Jun 2014 20:50:24 +0200 (CEST) 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.192.176; 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.192.176 as permitted sender) identity=mailfrom; client-ip=209.85.192.176; 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-pd0-f176.google.com) identity=helo; client-ip=209.85.192.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jordojw@gmail.com"; x-sender="postmaster@mail-pd0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Au4DAELxlVPRVcCwlGdsb2JhbABZhDiCbKd7BpobCBYPAQEBAQcLCwkSKoQcER0BGx4DEgkHNwIkAREBBQFXiAsBAxGdaoMSaosngXKDD5NKChknDWSEYxEBBQyFUYtKDzISgToEijKEb4sAkVQYKYUMHQ X-IPAS-Result: Au4DAELxlVPRVcCwlGdsb2JhbABZhDiCbKd7BpobCBYPAQEBAQcLCwkSKoQcER0BGx4DEgkHNwIkAREBBQFXiAsBAxGdaoMSaosngXKDD5NKChknDWSEYxEBBQyFUYtKDzISgToEijKEb4sAkVQYKYUMHQ X-IronPort-AV: E=Sophos;i="4.98,1003,1392159600"; d="scan'208";a="79193638" Received: from mail-pd0-f176.google.com ([209.85.192.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Jun 2014 20:50:24 +0200 Received: by mail-pd0-f176.google.com with SMTP id p10so5150356pdj.21 for ; Mon, 09 Jun 2014 11:50:22 -0700 (PDT) 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=rHwZ37c+8gGfpAV/W6+r546Ryjw/wtNZFTaOunUNDu0=; b=S1cPO38GxPwdDK8fYaUOlsriNA6X7E+J2OG96PZQw332ZbnRDTr98r2s+TvVR+DqBJ otGv3CBQeFhlA7yLZdAGN/amGWlqIG+0G5/WwbKy//hkVJZ5jZM6Iu6RwpVj731ylILG 36SE5D0R5AjH0qPd57XR4GngLCAk44OK8Iq5CpXJqg5AjytUX88LFkFCYrA5tEJfSC2N 31YuJkPjjBEGiONMB4NHz+Xz9ggIeCqc2in6WhN7MYrJFna1R+glqihuAgfSzFTi+rML b2fuBQjyrUB240tYyGanZo1X2yTLnY+r9EfbJFcfBp723qaQ1RV/9bliUxPVdXMXZZg3 e7sw== MIME-Version: 1.0 X-Received: by 10.67.3.166 with SMTP id bx6mr151881pad.7.1402339822707; Mon, 09 Jun 2014 11:50:22 -0700 (PDT) Received: by 10.70.65.229 with HTTP; Mon, 9 Jun 2014 11:50:22 -0700 (PDT) Date: Mon, 9 Jun 2014 11:50:22 -0700 Message-ID: From: Jordan W To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a11381400fcaab704fb6bae4d X-Validation-by: jordojw@gmail.com Subject: [Caml-list] Row-polymorphic type declarations --001a11381400fcaab704fb6bae4d Content-Type: text/plain; charset=UTF-8 I'd like to hear the answers to some questions asked on Twitter, that Anil began replying to: The original question was: Does anyone know why OCaml doesn't allow defining types with polymorphic row variables: or [> `Red ] but will infer them? Anil's answer was to use: type 'a t constraint 'a = [> `Red ] type 'a t constraint 'a = Here are the follow up questions that could still use some clarification: 1. Does anyone know how can we later instantiate the polymorphic row variables ".." with particular rows (both for obj methods and variants). Any good docs on this? How do we assert that another type/expression is equivalent to 'a t with 'a being a particular set of rows. Could someone give an example with a 2D point type type 'a twoDimensionalPoint constraint 'a = ;; How would we create another type threeDimensionalPoint that we assert is a two dimensional point with the polymorphic row variables being set to `z:int`? I understand type inference/checking automates most of this, but I often like to explicitly write type definitions to verify my own understanding of the program/inference. 3. Also curious why annotations in arguments don't require acknowledgment of row polymorphism let f (o:) = o#x + o#y;; 4. It appears there are two ways to write the row-polymorphic type annotation: type 'a t = ([> `Red ] as 'a) and type 'a t constraint 'a = [> `Red ]. Why are there two ways and what are the advantages? --001a11381400fcaab704fb6bae4d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I'd like to hear the answers to some questions asked o= n Twitter, that Anil began replying to:

The original question was: D= oes anyone know why OCaml doesn't allow defining types with polymorphic= row variables: <red: int; ..> or [> `Red ] but will infer them?
Anil's answer was to use:

=C2=A0 =C2=A0 type 'a t constr= aint 'a =3D [> `Red ]
=C2=A0 =C2=A0 type 'a t constraint = 9;a =3D <x:int; ..>

Here are the follow up questions that coul= d still use some clarification:

1. Does anyone know how can we later instantiate the polymorphic row va= riables ".." with particular rows (both for obj methods and varia= nts). Any good docs on this? How do we assert that another type/expression = is equivalent to 'a t with 'a being a particular set of rows.

Could someone give an example with a 2D point type

type 'a t= woDimensionalPoint constraint 'a =3D <x:int; y:int; ..>;;

= How would we create another type threeDimensionalPoint that we assert is a = two dimensional point with the polymorphic row variables being set to `z:in= t`? I understand type inference/checking automates most of this, but I ofte= n like to explicitly write type definitions to verify my own understanding = of the program/inference.

3. Also curious why annotations in arguments don't require ack= nowledgment of row polymorphism

=C2=A0 let f (o:&l= t;x:int; y:int; ..>) =3D o#x + o#y;;

4. It appears there are two = ways to write the row-polymorphic type annotation:
type 'a t =3D ([> `Red ] as 'a) and type 'a t constraint = 9;a =3D [> `Red ]. Why are there two ways and what are the advantages?
--001a11381400fcaab704fb6bae4d--