caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: ebreck@cs.cornell.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] changing the type of records using "with"
Date: Thu, 13 Jul 2006 11:43:39 +0900 (JST)	[thread overview]
Message-ID: <20060713.114339.07638100.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <C54E1B4E-FF0D-4B79-88CA-8088605DD721@cs.cornell.edu>

From: Eric Breck <ebreck@cs.cornell.edu>

> I noticed the following behavior of the typing system:
> 
> # type 'a foo = {a: 'a; b: int};;
> type 'a foo = { a : 'a; b : int; }
> # let one = { a = (); b = 5};;
> val one : unit foo = {a = (); b = 5}
> # let two = {one with a = "Hello"};;
> val two : string foo = {a = "Hello"; b = 5}
> 
> i.e. "{one with ... }" can have a different polymorphic type argument  
> than "one" does.  This has been handy for me on a couple of  
> occasions, but is it a documented feature that I can count on working  
> in future versions of ocaml, or is it a quirk of the current version?

This behaviour is intentional. My interpretation of the reference
manual is that {one with a = "Hello"} should be strictly equivalent to
{a = "Hello"; b = one.b}. As a result I would say that requiring two.a
and one.a to have the same type would depart from this specification.

Jacques Garrigue


      reply	other threads:[~2006-07-13  2:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-12 13:56 Eric Breck
2006-07-13  2:43 ` Jacques Garrigue [this message]

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=20060713.114339.07638100.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=ebreck@cs.cornell.edu \
    /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).