Label Names Space - philosophy or implementation?

pbrisset@eis.enac.dgac.fr
Wed, 24 Jul 1996 09:37:56 +0200

From: pbrisset@eis.enac.dgac.fr
Message-Id: <199607240738.JAA05990@concorde.inria.fr>
Date: Wed, 24 Jul 1996 09:37:56 +0200
To: John Gerard Malecki <johnm@vlibs.com>
Subject: Label Names Space - philosophy or implementation?
In-Reply-To: <199607230040.RAA11401@owl.vlibs.com>

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