From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA29438 for caml-red; Fri, 8 Dec 2000 10:07:45 +0100 (MET) 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 TAA03677 for ; Thu, 7 Dec 2000 19:36:26 +0100 (MET) Received: from postfix3.free.fr (postfix3.free.fr [212.27.32.22]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eB7IaQL01474 for ; Thu, 7 Dec 2000 19:36:26 +0100 (MET) Received: from sbuilders.com (paris11-nas6-50-148.dial.proxad.net [212.27.50.148]) by postfix3.free.fr (Postfix) with ESMTP id 9E5EB86EAB; Thu, 7 Dec 2000 19:36:24 +0100 (CET) Message-ID: <3A2FD846.B9EFE70F@sbuilders.com> Date: Thu, 07 Dec 2000 19:34:46 +0100 From: Maxence Guesdon Reply-To: max@sbuilders.com X-Mailer: Mozilla 4.73 [fr] (X11; I; Linux 2.2.16 i686) X-Accept-Language: fr, en MIME-Version: 1.0 To: Mattias Waldau Cc: Caml-List Subject: Re: Same label in different types, how do people solve this? References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: weis@pauillac.inria.fr Mattias Waldau a écrit : > > In Ocaml, you cannot have the same label in different types, see the example > below where > point_2d hides point_3d. > > How do people normally code around this restriction? One solution is using > objects, but what other solutions are there? Can 'Polymorphic variants' > solve this? In your example, and without objects, I would have chosen explicit names for labels, i.e. : type point_3d = { p3d_x:float; p3d_y:float; p3d_z:float; } type point_2d = { p2d_x:float; p2d_y:float; } It sure is kind of a pain to write, but it is much more easy to understand when you read it. With explicit labels, you "see" the type of toto in toto.p3d_x. I think not allowing to have the same label in different types is a great way to force developers to write cleaner code ;-) ---------------------- Maxence Guesdon http://maxence.guesdon.free.fr