English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
different records, same field name?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-03-03 (16:56)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] different records, same field name?
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.

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***