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 KAA23967 for caml-red; Fri, 8 Dec 2000 10:24: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 KAA31178 for ; Fri, 8 Dec 2000 10:22:38 +0100 (MET) Received: from dpt-info.u-strasbg.fr (dpt-info.u-strasbg.fr [130.79.6.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eB89Mcf14793 for ; Fri, 8 Dec 2000 10:22:38 +0100 (MET) Received: from lambda.u-strasbg.fr (lambda.u-strasbg.fr [130.79.90.63]) by dpt-info.u-strasbg.fr (8.9.3/8.9.3) with ESMTP id KAA19238; Fri, 8 Dec 2000 10:21:41 +0100 Received: from luther by lambda.u-strasbg.fr with local (Exim 3.16 #1 (Debian)) id 144JsD-00009O-00; Fri, 08 Dec 2000 10:31:25 +0100 Date: Fri, 8 Dec 2000 10:31:25 +0100 To: Jacques Garrigue Cc: mattias.waldau@abc.se, caml-list@inria.fr Subject: Re: Same label in different types, how do people solve this? Message-ID: <20001208103125.A556@lambda.u-strasbg.fr> References: <20001208102229N.garrigue@kurims.kyoto-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20001208102229N.garrigue@kurims.kyoto-u.ac.jp>; from garrigue@kurims.kyoto-u.ac.jp on Fri, Dec 08, 2000 at 10:22:29AM +0900 From: Sven LUTHER Sender: weis@pauillac.inria.fr On Fri, Dec 08, 2000 at 10:22:29AM +0900, Jacques Garrigue wrote: > From: "Mattias Waldau" > > > 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? > > There are various ways. The most common is to differentiate label > names (i.e. use x_3d and x_2d instead of x). Another more subtle one > is to put the definitions in deifferent modules (Point2d and Point3d) > so that you can specify exactly which label you want (Point2d.x or > Point3d.x). > > The last solution might be nicer if we had a > let open Module in > construct (would require 10 lines in the compiler) Is this not already possible ? i read about something similar in the docs somewhere ... Another idea would be to add some construct to use something like : type p3d = { x:float;y:float;z:float } type p2d = { x:float;y:float } and then be able to do : {p3d.x=10.;p3d.y=20.;p3d.z=30.} and {p2d.x=0; p2d.y=5} Would this be difficult to do ? Friendly, Sven Luther