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 KAA16356 for caml-red; Fri, 8 Dec 2000 10:04:27 +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 RAA06995 for ; Thu, 7 Dec 2000 17:50:43 +0100 (MET) Received: from localhost.localdomain (cartman118.zip.com.au [61.8.20.246]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eB7GoZL00143 for ; Thu, 7 Dec 2000 17:50:37 +0100 (MET) Received: from ozemail.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id DAA24329; Fri, 8 Dec 2000 03:49:17 +1100 Message-ID: <3A2FBF8D.997AFE7@ozemail.com.au> Date: Fri, 08 Dec 2000 03:49:17 +1100 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: 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=us-ascii Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr 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? Use distinct names :-) The 'correct' solution is a bit messy: use modules. > Also, I am a bit curious why it doesn't help to type explicitely, i.e. to > write > let x:point_3d={x=10.;y=20.;z=30.} ??? The RHS is typed without examining the type constraint on the LHS, then the constraint is checked. As in: let f (x : int) : int = "Hello" The type of f is first infered as 'a -> string, as if it had been written let f x = "Hello" then this type is unified with the declared type constraint. In your example, the type is infered to be point_2d, since you declared that second, and the field name 'x' is associated with this type: the previous binding of x to (a field of the) type point_2d is hidden. For your example try: module D3 = struct type point = { x:float; y:float; z:float; } end module D2 = struct type point = { x:float; y:float; } end ;; {D3.x=10.;D3.y=20.;D3.z=30.};; The 'field names' escape out of the type like a C enumeration, to allow type inference to deduce the type of a record literal. -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net