caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <j.d.yallop@sms.ed.ac.uk>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Oddness with recursive polymorphic variants
Date: Fri, 05 May 2006 09:04:01 +0100	[thread overview]
Message-ID: <445B06F1.2040901@sms.ed.ac.uk> (raw)
In-Reply-To: <20060504210319.5e05f7a6.nils.gesbert@ens.fr>

Thanks for all the replies.  My current understanding is as follows:

Given the types

    type f = [`A]
    type g = [f | `C]

then the following function is not acceptable

    let k (x:f) = (x:g)

because f and g are not unifiable: they are "closed rows" with different 
fields.  There are a number of ways to "open" the row, however:

    let k (#f as x:f) = (x:g)

This one is acceptable because the pattern "#f" means "an open row that 
includes all the tags in f".  (That's its type on the rhs, anyway.  The 
pattern (and the function) will accept exactly those tags in the type 
"f").  The type annotation on the parameter doesn't affect the type of 
"x", although the compiler does check that the type of the annotation 
and of the pattern can be unified.  The case where all the tags (only 
one in this case) are enumerated is treated identically:

    let k (`A as x:f) = (x:g)

Finally, the explicit coercion (:>).  Like the acceptable patterns, this 
"opens" the row, allowing it to be unified with "g" (or, indeed, with 
any other row type whose tag parameters don't clash with those of "f").

How does that sound?

Jeremy.


  parent reply	other threads:[~2006-05-05  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-04 15:50 Jeremy Yallop
2006-05-04 19:03 ` [Caml-list] " Nils Gesbert
2006-05-04 20:30   ` Nils Gesbert
2006-05-05  8:04   ` Jeremy Yallop [this message]
2006-05-04 15:54 Jeremy Yallop
2006-05-04 17:10 ` [Caml-list] " Luc Maranget
2006-05-04 18:26   ` Michael Wohlwend
2006-05-04 18:33   ` brogoff
2006-05-04 18:58     ` Jeremy Yallop
2006-05-05  0:01       ` brogoff
2006-05-05  6:43         ` Luc Maranget

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=445B06F1.2040901@sms.ed.ac.uk \
    --to=j.d.yallop@sms.ed.ac.uk \
    --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).