caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Row-polymorphic type declarations
@ 2014-06-09 18:50 Jordan W
  2014-06-10  9:25 ` Goswin von Brederlow
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jordan W @ 2014-06-09 18:50 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-11  2:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 18:50 [Caml-list] Row-polymorphic type declarations Jordan W
2014-06-10  9:25 ` Goswin von Brederlow
2014-06-10 14:13 ` Leo White
2014-06-11  2:20 ` Jacques Garrigue

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).