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 KAA23858 for caml-red; Fri, 8 Dec 2000 10:12:43 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA28502 for ; Fri, 8 Dec 2000 00:18:47 +0100 (MET) Received: from moutvdom00.kundenserver.de (moutvdom00.kundenserver.de [195.20.224.149]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eB7NIk515473 for ; Fri, 8 Dec 2000 00:18:46 +0100 (MET) Received: from [195.20.224.208] (helo=mrvdom01.schlund.de) by moutvdom00.kundenserver.de with esmtp (Exim 2.12 #2) id 144AJK-0002F2-00; Fri, 8 Dec 2000 00:18:46 +0100 Received: from drms-3e364b8f.pool.mediaways.net ([62.54.75.143] helo=ice.gerd-stolpmann.de) by mrvdom01.schlund.de with esmtp (Exim 2.12 #2) id 144AJG-0003pC-00; Fri, 8 Dec 2000 00:18:42 +0100 Received: from localhost (localhost [[UNIX: localhost]]) by ice.gerd-stolpmann.de (8.9.3/8.9.3) id AAA16273; Fri, 8 Dec 2000 00:18:32 +0100 From: Gerd Stolpmann Reply-To: gerd@gerd-stolpmann.de Organization: privat To: "Mattias Waldau" , "Caml-List" Subject: Re: Same label in different types, how do people solve this? Date: Fri, 8 Dec 2000 00:02:01 +0100 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain References: In-Reply-To: MIME-Version: 1.0 Message-Id: <00120800183206.00625@ice> Content-Transfer-Encoding: 8bit Sender: weis@pauillac.inria.fr On Wed, 06 Dec 2000, Mattias Waldau wrote: >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? The simplest way is to use different labels. Another solution is to wrap the type definition into modules: module P3d = struct type point_3d = { x:float; y:float; z:float; } end module P2d = struct type point_2d = { x:float; y:float; } end Now you can prefix the labels with the module identifiers: { P3d.x = 10.; P3d.y = 20.; P3d.z = 30. }, or { P2d.x = 10.; P2d.y = 20.} You can open the module whose type is used more frequently: open P2d { x = 10.; y = 20.; } Polymorphic variants are union types and not product types, so they do not help very much. Gerd -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: gerd@gerd-stolpmann.de Germany ----------------------------------------------------------------------------