From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id AFC36BBC1 for ; Mon, 3 Mar 2008 20:32:05 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAMLgy0dDWxLC/2dsb2JhbACBVqwM X-IronPort-AV: E=Sophos;i="4.25,439,1199660400"; d="scan'208";a="7957904" Received: from ip67-91-18-194.z18-91-67.customer.algx.net (HELO server1.bertec.net) ([67.91.18.194]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Mar 2008 20:32:05 +0100 Received: from kuba.bertec.net (kuba.bertec.net [192.168.2.16]) by server1.bertec.net (Postfix) with ESMTP id DC9DFCE05A for ; Mon, 3 Mar 2008 14:32:03 -0500 (EST) From: Kuba Ober To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] different records, same field name? Date: Mon, 3 Mar 2008 14:32:02 -0500 User-Agent: KMail/1.9.6 (enterprise 0.20071204.744707) References: <47CC2D9F.6050109@starynkevitch.net> In-Reply-To: <47CC2D9F.6050109@starynkevitch.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803031432.03002.ober.14@osu.edu> X-Spam: no; 0.00; basile:01 toplevel:01 compiler:01 inference:01 inference:01 ocaml:01 ocaml:01 compiler:01 cheers:01 wrote:01 wrote:01 compile:01 caml-list:01 int:01 int:01 On Monday 03 March 2008, Basile STARYNKEVITCH wrote: > mfmorss@aep.com wrote: > > In any case, is it possible to define and use different types of records, > > which nevertheless share some field names? I have had difficulty doing > > this in the toplevel. > > It is not possible, for a simple reason: > > Suppose you have two record type tr1 & tr2 sharing a common field name f > > type tr1 = { f : int; f1 : string } > > type tr2 = { f2 : float; f: int } > > Then the compiler won't be able to infer the type of function ff > retrieving this field f > > let ff x = x.f > > So the requirement that each field name is different is the price to pay > to have type inference. I think that type inference in OCaml sometimes gets in the way of other language features. I'd much rather see OCaml go in a direction where type inference is performed on "as far as it can go" basis. In the cited example, if the compiler couldn't infer the type, it should simply remind the user to use explicit type as appropriate in such case. While I do admit that this may cause some "silly" behavior, where changes in unrelated code can cause compile errors elsewhere, this should be naturally shielded by module boundaries. So, as far as I can see, it wouldn't suddenly break precompiled modules, at least. Cheers, Kuba