From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id KAA21525 for caml-redistribution; Wed, 24 Jul 1996 10:10:06 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id JAA21385 for ; Wed, 24 Jul 1996 09:38:01 +0200 From: pbrisset@eis.enac.dgac.fr Received: from apollo12.eis.enac.dgac.fr (apollo12.eis.enac.dgac.fr [192.70.3.82]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id JAA05990 for ; Wed, 24 Jul 1996 09:38:01 +0200 (MET DST) Message-Id: <199607240738.JAA05990@concorde.inria.fr> Received: from apoge.eis.enac.dgac.fr by apollo12.eis.enac.dgac.fr with SMTP (1.37.109.4/17.1) id AA03323; Wed, 24 Jul 96 09:37:58 +0200 Received: by apoge.eis.enac.dgac.fr (1.38.193.4/16.2) id AA02357; Wed, 24 Jul 1996 09:37:56 +0200 Date: Wed, 24 Jul 1996 09:37:56 +0200 To: John Gerard Malecki Cc: caml-list@pauillac.inria.fr Subject: Label Names Space - philosophy or implementation? In-Reply-To: <199607230040.RAA11401@owl.vlibs.com> References: <199607230040.RAA11401@owl.vlibs.com> Sender: weis John Gerard Malecki writes: > > A co-worker has (vehemently) pointed out to me that record label names > cannot be shared. For example, the following fails > > type foo = { name : string; x : int } > let a = { name = "foo"; x = 1 } > > type bar = { name : string; y : float } > let b = { name = "bar"; y = 9. } > ... > field with a standardized label. This makes it easier for him to > write printers for his data-structure. Does anyone have a > recommendation to make to him? type 'a foobar = { name : string; x : 'a} let print_name {name = s} = print_string s print_name { name = "foo"; x = 1 } print_name { name = "bar"; x = 9. } or using classes and inheritance (I do not like it but ...) : class named (s:string) = val private name = s method name = name end class foo n (x:int) = inherit named n val private x = x method x = x end class bar n (y:float) = inherit named n val private y = y method y = y end let print_name x = print_string x#name print_name (new foo "foo" 1) print_name (new bar "bar" 9.) My 0.02 euros... --Pascal