caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jordan W <jordojw@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Row-polymorphic type declarations
Date: Mon, 9 Jun 2014 11:50:22 -0700	[thread overview]
Message-ID: <CAPOA5_7swJ1tQ+S63TAHE+hXxQp8uqiesHJAFxkcNvSxgjQ_6g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1507 bytes --]

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: <red: int; ..> or [> `Red ]
but will infer them?

Anil's answer was to use:

    type 'a t constraint 'a = [> `Red ]
    type 'a t constraint 'a = <x:int; ..>

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 = <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: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:<x:int; y:int; ..>) = 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?

[-- Attachment #2: Type: text/html, Size: 1762 bytes --]

             reply	other threads:[~2014-06-09 18:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 18:50 Jordan W [this message]
2014-06-10  9:25 ` Goswin von Brederlow
2014-06-10 14:13 ` Leo White
2014-06-11  2:20 ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPOA5_7swJ1tQ+S63TAHE+hXxQp8uqiesHJAFxkcNvSxgjQ_6g@mail.gmail.com \
    --to=jordojw@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).