caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: florentflament@aist.enst.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] strange behavior with record type definition
Date: Sun, 13 Nov 2005 09:12:53 +0900 (JST)	[thread overview]
Message-ID: <20051113.091253.108310233.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <4375FACF.3040906@aist.enst.fr>

From: Florent <florentflament@aist.enst.fr>

> Ok but with these two record types defined :
>     type t0 = { x : int ; y : int } ;;
>     type t1 = { x : int } ;;
> 
> There is no ambiguity about the following expression's type:
>     { x = 0 ; y = 0 } ;;
> Why can't the t0 type be infered ?
> 
> And with this function definition,
>     let get_y (t:t0) = t.x ;;
> I explicitly say to the compiler that t is of type t0, so why does the 
> compiler infer a t1 type when trying to get the x label of a t0 type value ?

It is not a question about it being possible or not (it is possible,
and can even be made "principal"), but whether we want it in the
language or not.
Essentially, ocaml has two kinds of records: explicitly
declared records, and objects. Of course, objects as records
are not very efficient, but in many cases this doesn't matter.
You can even find a syntax extension to do it with the same syntax as
records.
  http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html

Knowing this, the choice is currently to make explicit records
non-ambiguous. This way you just have to look at any of the the
labels to know exactly which type is involved. This could be changed,
but you would loose this property.  Which would be fine with me, as
long as the information is still still easy to deduce without relying
on type inference.

Jacques Garrigue


  parent reply	other threads:[~2005-11-13  0:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-11 22:59 Florent
2005-11-11 23:52 ` [Caml-list] " Jon Harrop
2005-11-12  0:15 ` Michael Wohlwend
2005-11-12  0:20 ` Martin Jambon
2005-11-12 10:58   ` Florent
2005-11-12 12:12     ` skaller
2005-11-12 12:20       ` Nicolas Cannasse
2005-11-12 12:51         ` skaller
2005-11-12 14:15           ` Michael Wohlwend
2005-11-12 14:45             ` skaller
2005-11-12 15:26             ` Christophe TROESTLER
2005-11-12 14:23           ` Florent
2005-11-12 15:32             ` Christophe TROESTLER
2005-11-12 16:50             ` Florian Weimer
2005-11-13  0:12             ` Jacques Garrigue [this message]
2005-11-13 12:50               ` Florent

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=20051113.091253.108310233.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=florentflament@aist.enst.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).