From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 67F51BB81 for ; Sun, 13 Nov 2005 01:13:07 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAD0D6tP005261 for ; Sun, 13 Nov 2005 01:13:07 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA00788 for ; Sun, 13 Nov 2005 01:13:06 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAD0D4ph005256 for ; Sun, 13 Nov 2005 01:13:05 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id jAD0CufV000248; Sun, 13 Nov 2005 09:12:56 +0900 (JST) Date: Sun, 13 Nov 2005 09:12:53 +0900 (JST) Message-Id: <20051113.091253.108310233.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 From: Jacques Garrigue In-Reply-To: <4375FACF.3040906@aist.enst.fr> References: <4375DDFC.9060802@motion-twin.com> <1131799890.18524.14.camel@rosella> <4375FACF.3040906@aist.enst.fr> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43768512.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43768510.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 compiler:01 compiler:01 ocaml:01 syntax:01 syntax:01 ocaml:01 inference:01 explicitly:01 explicitly:01 essentially:01 int:01 int:01 jacques:01 jacques:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Florent > 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